从numpy数组中提取类

我有一个numpy的数据数组

data = np.random.random((5, 5))

and another numpy array of equal shape masking the first one with classes from 0 to n:

>>> mask
array([[3, 3, 1, 1, 0],
       [2, 0, 1, 2, 2],
       [0, 1, 0, 0, 3],
       [2, 1, 1, 0, 2],
       [0, 2, 3, 0, 2]])

What's the best way to compute a two-dimensional array with n rows, where each row contains all elements from data with class row_idx (described by mask)?

评论