mathemagician
mathemagician

Reputation: 183

maximizing over a 4D array in Python

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

Upvotes: 0

Views: 816

Answers (1)

Matt S
Matt S

Reputation: 1454

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))

Upvotes: 2

Related Questions