Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Numpy operations for generating a 2D array from a 3D array

I have an array A with shape [2, 512, 21128] and another list [7,41]

I want to create a new array with shape [2,21128] from A[0,7,:] and A[1,41,:].

I can use a loop to do such things, is there any convenient way to do this? I try to find it online but I actually do not know how to ask this question.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use advanced indexing:

arr = np.random.rand(2, 512, 21128)
out = arr[[0, 1], [7, 41]]

out.shape:

(2, 21128)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading