Why would xcorr and xcorr2 be quite different here? M1 and M2 are numpy matrices. M1.shape[0] = M2.shape[0]. xcorr is what I would expect with this operation, but xcorr2 is something totally different and has imaginary numbers. xcorr does not have imaginary numbers. Answer Try giving xcorr and xcorr2 dtype=complex. According to scipy docs, the output from both fft and

# Tag: numpy

## TypeError: unhashable type: ‘numpy.ndarray’, Counter rows

I’m trying to view the frequency of the elements in a 2d array as in the code: Expected result: ({(22, 66): 2, (33, 77): 1, (55, 99): 1}) But I get: Answer Create a list of tuples: (tuples are hashable) Now Counter works: numpys own unique also works

## Not able to read the correct values from a binary file in python

I created and wrote double (data type) values into a binary file. The file does not contain any headers. It is just raw data written into the file using QDataStream in Qt. I am trying to read the values in a python (version 3.6.9) script, however, the data that is read in the python script is not corect. The same

## How to create a numpy 2-D array whose elements depend on elements of two lists already fixed

Example: Let and I would like to create a matrix C of size (5,5) whose elements are where f is a fixed function for example f(x,y) = x*y + x + y which means In the case where c_ij depends on i and j only and does not depend on the lists A and B, we can use np.fromfunction(lambda i,j:

## Finding location of subarray in numpy array

I want to find the location of a subarray in an numpy array. For example, if the large array is of shape (10000, 10, 10, 10), namely 10000 arrays of shape (10,10,10) and I want to find the location of the subarray of shape (3,3,3) as follows: So I will know that at the location of n, i, j, k

## How to get standard deviation across multiple 2d arrays by cell?

I have 16 2d-arrays, each in a shape of [16000, 16000], which means one array has 256000000 cells. I want to have a std_array that is the standard deviation of each cell in the 16 arrays. I tried something but failed, and my questions are in bold. Here’s my attempt. For example (simplified 3*3 arrays): However, the np.std function only

## Fastest way to find a 2d array inside another array that holds multiple 2d arrays

Hi I’m trying to perform a search operation in an array that contains multiple 2d arrays comparing it’s itens to a specific array. I managed to do it using a for loop iterating trough the itens inside the big array but I have to perform this search 10^6 times and the length of this for loop can grow up to

## Solve linear system in python with different set of roots

I’m having a problem where I have this linear system for example I need to solve for x1, x2, and x3 but every library I used gave me only x1=x2=x3=0 as a solution it’s correct but the system accepts other solution. I am looking for a solution to avoid zeros as answer. Thanks for helping. Answer That’s more of a

## I am getting ValueError: invalid literal for int() with base 10 with np.where function

I want to change ‘not available’ value in a df column into 0, and for the rest of the values to change them into integers. Unique values in the column are: I run the following code to change values to integers: I expect that the above would turn all values into integers, yet I get the value error Any suggestion

## pandas rename multiple columns using regex pattern

I have a dataframe like as shown below I would like to remove the keyword US – from all my column names I tried the below but there should be better way to do this But my real data has 70 plus columns and this is not efficient. Any regex approach to rename columns based on regex to exclude the