使用numpy向索引列表中的数组添加一个

I have a 2D array, a, and another array, index_list, that is a list of valid indices for that 2D array. The same index may appear more than once. I want to add one to that 2D array at every index that appears in the list of indices. If an index appears n times, I want to add one n times.

例如,给定:

a = np.arange(9).reshape((3,3))
index_list = np.array([[0,0],[0,1],[2,2],[2,2]])

我想要一个函数返回:

[[1,2,2],
 [3,4,5],
 [6,7,10]]

我怎么能用numpy做到这一点?

评论