Skip to content

Tag: numpy

How to slice and calculate the pearson correlation coefficient between one big and small array with “overlapping” windows arrays

Suppose I have two very simple arrays with numpy: I would like to find which slice of array reference has the highest pearson’s correlation coefficient with array probe. To do that, I would like to slice the array reference using some sort of sub-arrays that are overlapped in a for loop, which means I shift one element at a time

How to create a tensor from a list of matrices in numpy?

How do I create a tensor T that is 3x2x3; as in, T[:,:,0] = A, T[:,:,1] = B, and T[:,:,2] = C? Also I may not know the number of matrices that I may be given before run time, so I cannot explicitly create an empty tensor before hand and fill it. I tried, but that gives me an array

Appending 1D Ndarray to 2D Ndarray

I’m attempting to append a 1D array which have generated by appending elements one at a time to a 2D array as a new row in the array. I’m pretty lost as to why this code doesn’t work? They are both arrays of 5 elements, but get the following error? “ValueError: all the input arrays must have same number of

Matrix row masking at different indices

I have an 2-D array that I want to find the max value per row and then find the next max-value that is not within +/- n of the previous value. For example I have the following matrix: Now I’d like to get the next max value not within say +/- 2 of the current max. Here is what I

Transform a 3D numpy array to 1D based on column value

Maybe this is a very simple task, but I have a numpy.ndarray with shape (1988,3). I want to create a 1D array with shape=(1988,) that will have values corresponding to the column of my 3D array that has a value of 1. For example, How can I do this? Answer You can use numpy.nonzero: Output: array([0, 1, 2, 1, 0,