In other words, I want to do something like
A[[-1, 0, 1], [2, 3, 4]] += np.ones((3, 3))
instead of
A[-1:3, 2:5] += np.ones((1, 3))
A[0:2, 2:5] += np.ones((2, 3))
If I understand correctly, you can do what you want to do with the following:
A[[[-1],[0],[1]],[2,3,4]] += np.ones((3, 3))
However, the numpy folks made a function, ix_, to make it a little bit easier:
A[np.ix_([-1,0,1],[2,3,4])] += np.ones((3, 3))
I hope that helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.