Extracting specific columns in numpy array

前端 未结 9 1307
隐瞒了意图╮
隐瞒了意图╮ 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

    if you want to extract only some columns:

    idx_IN_columns = [1, 9]
    extractedData = data[:,idx_IN_columns]
    

    if you want to exclude specific columns:

    idx_OUT_columns = [1, 9]
    idx_IN_columns = [i for i in xrange(np.shape(data)[1]) if i not in idx_OUT_columns]
    extractedData = data[:,idx_IN_columns]
    

提交回复
热议问题