Skip to content

Tag: numpy-ndarray

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

Replacing chunks of numpy array on condition

Let’s say I have the following numpy array, of 1’s and 0’s exclusively: I want to group all elements into chunks of 3, and replace the chunks by a single value, based on a condition. Let’s say I want [0,1,1] to become 5, and [0,1,0] to become 10. Thus the desired output would be: All possible combinations of 1’s and