[SOLVED] Reshaping/Grouping a 3D numpy array in a performant way

Issue

I currently have a list of numpy arrays of shape (72(x), 4480(y),4(z)). What would be the most performant way to reshape or group these into something such as a hashmap where the Y would be unique and it would pull all of the Z’s into each Y index while keeping the x index?

Thank you.

Solution

Use reshape() to transform your dimensions in numpy.

arr = np.repeat([1,2,3],430080).reshape(72,4480,4)
print(arr.shape)
print(arr.reshape(72,-1).shape)
(72, 4480, 4)
(72, 17920)

Answered By – JAdel

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *