For example, i have an complex array of shape (3,3,3) and i want to find angle of the element when magnitude of the array along axis 2 is maximum. That is,
a = np.random.random((3, 3, 3)) + 1j * np.random.random((3, 3, 3))
amp3d = np.abs(a)
amp2d = np.max(amp3d, axis=2)
angle2d = np.zeros_like(amp2d)
for i in range(a.shape[0]):
for j in range(a.shape[1]):
for k in range(a.shape[2]):
if amp3d[i, j, k] == amp2d[i,j]:
angle2d[i, j] = np.angle(a[i, j, k])
Of course i can loop, but i guess there is exist a pretty pythonic way to accomplish this task
In Matlab it would be look similar to np.angle(a[np.argmax(a, axis=2)])
Thanks!