【问题标题】:Mask an 2Darray row wise by another array用另一个数组按行屏蔽二维数组
【发布时间】:2022-12-02 18:08:33
【问题描述】:

Consider the following 2d array:

>>> A = np.arange(2*3).reshape(2,3)
array([[0, 1, 2],
       [3, 4, 5]])

>>> b = np.array([1, 2])

I would like to get the following mask from A as row wise condition from b as an upper index limit:

>>> mask
array([[True, False, False],
       [True, True, False]])

Can numpy do this in a vectorized manner?

    标签: python numpy


    【解决方案1】:
    【解决方案2】: