Subsetting a 2D numpy array

前端 未结 4 1221
暖寄归人
暖寄归人 2020-11-27 07:28

I have looked into documentations and also other questions here, but it seems I have not got the hang of subsetting in numpy arrays yet.

I have a numpy array, and

4条回答
  •  -上瘾入骨i
    2020-11-27 07:38

    Another quick way to build the desired index is to use the np.ix_ function:

    >>> a[np.ix_(n1, n2)]
    array([[ 0,  1,  2,  3,  4],
           [10, 11, 12, 13, 14],
           [20, 21, 22, 23, 24],
           [30, 31, 32, 33, 34],
           [40, 41, 42, 43, 44]])
    

    This provides a convenient way to construct an open mesh from sequences of indices.

提交回复
热议问题