I have a 4D array, which is defined as follows:
B = np.array(
[[[[0.5000, 0.5625],
[0.5000, 0.5625]],
[[1.2500, 0.5000],
[0.5625, 0.6875]],
[[0.5625, 0.6250],
[0.5000, 0.5625]]]]
)
I want to take the max of each 2D matrix, such that I get a result of:
array([0.5625, 1.250, 0.6250])
Similarly, I want to take the min of each 2D matrix, such that I get a result of:
array([0.5000, 0.5000, 0.5000])
However, when doing np.max(B, axis=0)
, np.max(B, axis=1)
, np.max(B, axis=2)
, or np.max(B, axis=3)
-- none of these gives the right answer. Is there another argument I need to specify to do this operation?
The correct solution should not use any loops and ideally one function call.