Stacy
Stacy

Reputation: 43

Find max indices along z axis of numpy 3d array

I have a 3d numpy array. I'd like to find the largest coordinate at each [x,y] grid point of non-zero elements along the z axis of the array. This would result in a 2d array filled with z index values. How can I do that?

Upvotes: 2

Views: 2725

Answers (1)

2cynykyl
2cynykyl

Reputation: 1083

Use the amax function in Numpy, and specify the axis along which you want the maximum to be taken:

ans = numpy.amax(arr_3D, axis=2)

Upvotes: 1

Related Questions