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
Tag: numpy-ndarray
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
Fastest way to get dot product of a matrix and each point in the given array
I have an array Nx3 of N points, each one has X, Y and Z coordinate. I need to rotate each point, so i have the rotation matrix 3×3. To do this, i need to get dot product of the rotation matrix and each point. The problem is the array of points is quite massive (~1_000_000x3) and therefore it takes
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
IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (2,) (3,)
I have an np.ndarray of shape (5, 5, 2, 2, 2, 10, 8) named table. I can succesfully slice it like this: But for some reason when I try to specify three values for dimension 5 (of length 10) like this: I get: The same is for: This does not happen with: which output the correct result. I tried 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
Convert x same size 2D numpy arrays to a 2+x column data frame
I have two ndarrays of size (m x n), and two lists of length m and n respectively. I want to convert the two matrices to a dataframe with four columns. The first two columns correspond to the m and n dimensions, and contain the values from the lists. The next two columns should contain the values from the two