如何在numpy数组中选择特定的列?

Gau*_*wla 5 python arrays numpy

假设我有20x100 numpy阵列.我想选择除50号之外的所有列.所以我跟随这​​个线程在numpy数组中提取特定的列, 但它没有帮助.我试过用

 x=Z[:,[:49,51:]] 
Run Code Online (Sandbox Code Playgroud)

但是给了错误.在R中很容易做到这一点

x=Z[,c(1:49,51:100)] 
Run Code Online (Sandbox Code Playgroud)

但在Python中无法弄明白.请帮忙.谢谢

DSM*_*DSM 4

在这里获得类似 R 的语法的一种方法是使用np.r_

>>> Z = np.arange(2000).reshape(20, 100)
>>> Z.shape
(20, 100)
>>> x = Z[:,np.r_[:49,50:100]]
>>> x.shape
(20, 99)
>>> x[0,48:52]
array([48, 50, 51, 52])
Run Code Online (Sandbox Code Playgroud)

我们看到 中缺少第 50 列(编号为 49)x