I have 2 arrays:
mask: with value 0 and 1, dtype=uint8
>>> mask
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[1, 1, 1, ..., 0, 0, 0],
...,
[1, 1, 1, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
and prova_clip
>>> prova_clip
array([[289, 281, 271, ..., 257, 255, 255],
[290, 284, 268, ..., 260, 260, 259],
[294, 283, 264, ..., 265, 263, 257],
...,
[360, 359, 360, ..., 335, 338, 331],
[359, 364, 369, ..., 337, 342, 339],
[358, 363, 368, ..., 332, 331, 332]], dtype=uint16)
I wish to use a code saving method to mask prova_clip with mask in order to have
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[294, 283, 264, ..., 0, 0, 0],
...,
[360, 359, 360, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint16)
Am I missing something? This seems as simple as:
Here’s an example:
You could also do it the complicated way which will modify an array in place.
Finally, there’s
numpy.where: