-1

Given that I have a numpy array of three dimension [3,500,500], how can I extract one dimension as [1,500,500]?

import numpy as np
my_array = np.ones((3,500,500),dtype=int,order='C')
print (my_array)
1
  • which one ones you need? Commented Dec 13, 2013 at 22:22

2 Answers 2

5

Those ones?

>>> my_array[0,:,:]
array([[1, 1, 1, ..., 1, 1, 1],
       [1, 1, 1, ..., 1, 1, 1],
       [1, 1, 1, ..., 1, 1, 1],
       ...,
       [1, 1, 1, ..., 1, 1, 1],
       [1, 1, 1, ..., 1, 1, 1],
       [1, 1, 1, ..., 1, 1, 1]])
>>> my_array[0,:,:].shape
(500, 500)
Sign up to request clarification or add additional context in comments.

1 Comment

You can just use my_array[0], or my_array[:1] if you want to keep the first axis.
1

maybe you mean transposed:

my_array = np.random.rand(3,3)

[[0.03639883, 0.47393186, 0.25823457],
 [0.3732702 , 0.43692148, 0.13893397],
 [0.11873897, 0.71504391, 0.34635178]]

my_array.T[0]:
[0.03639883, 0.3732702, 0.11873897]
my_array.T[1]:
[0.47393186 , 0.43692148, 0.13893397]
my_array.T[2]:
[0.11873897, 0.71504391, 0.34635178]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.