Suppose I have the following numpy array:
>>> a=np.zeros(10)
>>> a
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
I can use numpy.ufunc.at to change this array:
>>> np.add.at(a, [0,3], 2)
>>> a
array([ 2., 0., 0., 2., 0., 0., 0., 0., 0., 0.])
If I try to use a matrix now, then I assume that this method does not work:
>>> m=np.zeros(16).reshape(4,4)
>>> m
array([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]])
>>> np.add.at(m, [(0,0),(1,1)], 2)
>>> m
array([[ 0., 4., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]])
My expectation based on supplying a list of tuples [(0,0),(1,1)]would be:
[[ 2., 0., 0., 0.],
[ 0., 2., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]]
Any suggestions on what I'm using as a list of indexes in numpy.ufunc.atto get this matrix?