【问题标题】:Select specific columns in NumPy array using colon notation使用冒号表示法选择 NumPy 数组中的特定列
【发布时间】:2017-11-06 15:18:13
【问题描述】:

我有一个 40000 x 60 的 Numpy 数组,我想这样:

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

显然,它不起作用。有没有比串联更聪明的方法?

【问题讨论】:

    标签: python numpy indexing


    【解决方案1】:

    使用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
    

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 2023-03-29
    • 2014-05-20
    • 2019-11-01
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    相关资源
    最近更新 更多