Extracting specific columns in numpy array

前端 未结 9 1282
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 02:27

This is an easy question but say I have an MxN matrix. All I want to do is extract specific columns and store them in another numpy array but I get invalid syntax errors. He

9条回答
  •  长情又很酷
    2020-11-28 02:36

    One more thing you should pay attention to when selecting columns from N-D array using a list like this:

    data[:,:,[1,9]]
    

    If you are removing a dimension (by selecting only one row, for example), the resulting array will be (for some reason) permuted. So:

    print data.shape            # gives [10,20,30]
    selection = data[1,:,[1,9]]
    print selection.shape       # gives [2,20] instead of [20,2]!!
    

提交回复
热议问题