使用冒号表示法在NumPy数组中选择特定列 [英] Select specific columns in NumPy array using colon notation

查看:87
本文介绍了使用冒号表示法在NumPy数组中选择特定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个40000乘60 Numpy阵列,我想这样:

I have a 40000 by 60 Numpy array, and I want to sth like this:

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

显然,它不是工作。有没有比连接更聪明的方法呢?

Obviously, it does not work. Is there a smarter way to do this than concatenation?

推荐答案

使用 np.r _ -

Use 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

这篇关于使用冒号表示法在NumPy数组中选择特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆