Python Forum
Looping in a 3D matrix - desperate for assistance!
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping in a 3D matrix - desperate for assistance!
#2
You can use the max function from numpy, choosing the axis where you want to perform the operation:
# Create a dummy array of 5 x 3 x 3 where 1st dimension is time and the others are space position.
>>> import numpy as np
>>> q = np.array(range(5*3*3))
>>> q.shape = (5, 3, 3)
# Get the maximum for all the elements
>>> np.max(q)
44
# Get the max for each lat, lon
>>> np.max(q, axis=0)
array([[36, 37, 38],
       [39, 40, 41],
       [42, 43, 44]])
# Get the max for only the times 2 and 3:
>>> np.max(q[2:4, ...])
35
Try using array selection operations (slices, masks) and playing with the axis parameter to obtain the values you want.
Reply


Messages In This Thread
RE: Looping in a 3D matrix - desperate for assistance! - by killerrex - May-14-2018, 10:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need desperate help needHelpp 2 3,357 Aug-06-2017, 06:02 PM
Last Post: eyn2k

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020