Increment given indices in a matrix

后端 未结 2 1128
不知归路
不知归路 2020-12-03 23:40

Briefly: there is a similar question and the best answer suggests using numpy.bincount. I need the same thing, but for a matrix.

I\'ve got two arrays:

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 00:13

    m1 = m.view(numpy.ndarray) # Create view
    m1.shape = -1 # Make one-dimensional array
    m1 += np.bincount(a+m.shape[1]*b, minlength=m1.size)
    

提交回复
热议问题