Skip to content
Advertisement

Tag: numpy-ndarray

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

Iterate over inner axes of an array

I want to iterate over some inner dimensions of an array without knowing in advance how many dimensions to iterate over. Furthermore I only know that the last two dimensions should not be iterated over. For example assume the array has dimension 5 and shape (i,j,k,l,m) and I want to iterate over the second and third dimension. In each step

Sorting lists with multiple tie breakers

I have data in an array like so: I want to sort it by the amount of non-10 values, and I also want to sort it in ascending order for rows, and in descending order of number of 10s: Output: I want to implement a tie breaker system so that if the amount of 10s the same, it now orders

Delete all zeros slices from 4d numpy array

I pretend to remove slices from the third dimension of a 4d numpy array if it’s contains only zeros. I have a 4d numpy array of dimensions [256,256,336,6] and I need to delete the slices in the third dimension that only contains zeros. So the result would have a shape like this , e.g. [256,256,300,6] if 36 slices are fully

Create NumPy array from list of tuples

I have data in the following format: And I want use this information to create a NumPy array that has the value 1.0 in position 2, value 2.5 in position 6, etc. All positions not listed in the above should be zeroes. Like this: Answer First reformat the data: And then create the array: Note that you need to convert

How to get this result when multiplying 1d-array by 2d-array?

I am struggling to figure out, how the output is calculated can you please explain? I have this multiplied by this array : c = np.array([3267. , 3375.9, 3484.8, 3630., 3740.]) the output is: array([1050885., 1068309., 1085733., 1103157., 1120581.]) Answer Grasping at straws because it feels like there’s not enough information to solve this. But, here is one way to

3d numpy array perform operation along column i only

I have a 3d numpy array like this (as an example) I want to apply the following operations only to elements within the column with index 1 in the inner dimension. The elements are [-2,6,10,14] for the example above. The operations would be: Can someone help me? I have looked into several NumPy methods but can’t seem to adapt to

Advertisement