maximizing over a 4D array in Python

727 Views Asked by At

So I have a x b x c x d array in Python. Call it S. I want to create an array a x b, call it V so that V[i,j] equals the highest value that S[i,j,., .] seen as a c x d array takes. I also want to know the coordinates (roughly 0

1

There are 1 best solutions below

0
On BEST ANSWER

Use numpy to get the maximum value along an axis. The axis argument refers to the dimension that you are taking the max along.

import numpy as np

a,b,c,d = 3,4,5,6 #Whatever you want
S = np.random.random( (a,b,c,d))
V = np.max(S.reshape( (a,b,c*d) ), axis = 2)
#OR
V = np.max(np.max(S,axis = 3),axis = 2)
#OR
V = np.max(S, axis = (2,3))