Say I have a matrix ‘R’ filled with random integers
import numpy as np
matR = np.random.randint(-10,10,size=(4,6))
>>> matR = [[-4 -4 1 -8 -2 5]
[ 9 2 -4 -1 4 2]
[ 7 8 -2 -9 3 8]
[ 9 -3 3 6 4 3]]
Now I know I can sample it like this:
>>> matR[::2,::2] = [[-4 1 -2]
[ 7 -2 3]]
What I really want, however, is a clean way of doing this:
>>> matR.?? = [[-4 0 1 0 -2 0]
[ 0 0 0 0 0 0]
[ 7 0 -2 0 3 0]
[ 0 0 0 0 0 0]]
I’d like to avoid python loops, it would be easy that way using enumerate.
Do you want something like this?