Extract Specific RANGE of columns in numpy array Python

前端 未结 2 1375
长情又很酷
长情又很酷 2020-12-30 04:14

I have an array :

e = np.array([[ 0,  1,  2,  3, 5, 6, 7, 8],
              [ 4,  5,  6,  7, 5, 3, 2, 5],
              [ 8,  9, 10, 11, 4, 5, 3, 5]])
         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 04:55

    You can just use e[:, 1:5] to retrive what you want.

    In [1]: import numpy as np
    
    In [2]: e = np.array([[ 0,  1,  2,  3, 5, 6, 7, 8],
       ...:               [ 4,  5,  6,  7, 5, 3, 2, 5],
       ...:               [ 8,  9, 10, 11, 4, 5, 3, 5]])
    
    In [3]: e[:, 1:5]
    Out[3]:
    array([[ 1,  2,  3,  5],
           [ 5,  6,  7,  5],
           [ 9, 10, 11,  4]])
    

    https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

提交回复
热议问题