Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python np.array的裁剪部分_Python_Arrays_Numpy - Fatal编程技术网

Python np.array的裁剪部分

Python np.array的裁剪部分,python,arrays,numpy,Python,Arrays,Numpy,我有一个numpy数组 A.shape (512,270,1,20) 我不想使用维度4中的所有20层。新数组应该是 Anew.shape (512,270,1,2) 所以我想从中裁剪出数组A的两个“切片”,答案是: start = 4 # Index where you want to start. Anew = A[:,:,:,start:start+2] 可以使用而不是切片表示法来选择最终维度中的任意索引序列: x = np.zeros((512, 270, 1, 20)) y = x

我有一个numpy数组

A.shape
(512,270,1,20)
我不想使用维度4中的所有20层。新数组应该是

Anew.shape
(512,270,1,2)
所以我想从中裁剪出数组A的两个“切片”,答案是:

start = 4 # Index where you want to start.
Anew = A[:,:,:,start:start+2]
可以使用而不是切片表示法来选择最终维度中的任意索引序列:

x = np.zeros((512, 270, 1, 20))
y = x[..., [4, 10]] # the 5th and 11th indices in the final dimension
print(y.shape)
# (512,270,1,2)

谢谢,如果我不想在第一、第五、第十一场比赛中截取一个被截取的球。。。切片?读这篇优秀的文章,明白了,谢谢。只需使用[-1,-..,-..]即可到达切片,也可查看不规则切片。因此,您可以重新执行
A[:,:,:,[1,4,5]]