I have the following algorithm:
import numpy as np
matriz = np.array(np.zeros(81).reshape(9, 9))
for i in range(1, matriz.shape[0], 3):
for j in range(1, matriz.shape[1], 3):
matriz[i, j] = 255
print(matriz)
It generates the following array:
[[ 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 255. 0. 0. 255. 0. 0. 255. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 255. 0. 0. 255. 0. 0. 255. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 255. 0. 0. 255. 0. 0. 255. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
That is, this algorithm traverses this matrix, with a 3x3 mask, and includes the value 255 in its central position.
I'm working with image processing and this operation has proven to be very costly when I use large images.
Can anyone tell me if there is another way to do this, which I propose, more quickly?