2017-06-05 65 views
3

在与NumPy阵列特定列我有一个40000 60 numpy的数组,我想某事像这样:选择使用冒号表示法

mat[:,[0:13,19:23,23:31,39:59]] 

很显然,这是行不通的。有没有比拼接更聪明的方法?

回答

3

使用np.r_ -

mat[:,np.r_[0:13,19:23,23:31,39:59]] 

采样运行 -

In [48]: mat = np.random.rand(100,1000) 

In [50]: mat[:,np.r_[0:13,19:23,23:31,39:59]].shape 
Out[50]: (100, 45) 

In [51]: 13+4+8+20 
Out[51]: 45 
+0

非常感谢! –