0
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 me the following matrix:
[[ 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 am working with image processing and this operation has proved highly costly when using large images.
Would anyone know if there’s another way to do that, which I propose, faster?
Thanks @João Victor! I’ll search on multi thread.I think this solves my problem.
– Danilo