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)
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)
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)
my_array[0], or my_array[:1] if you want to keep the first axis.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]