![](/img/trans.png)
[英]Python/Numpy: How to extract interior of any dimension of numpy array?
[英]how to extract required dimension from a numpy array
鉴于我有一个三维[3,500,500]的numpy数组,我怎么能提取一个维度为[1,500,500]?
import numpy as np
my_array = np.ones((3,500,500),dtype=int,order='C')
print (my_array)
那些?
>>> 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 = 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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.