0

Say I have an image array:

raster.shape => (3,100,100)

I generate a mask of all the places where red is saturated:

mask = np.where(raster[0,:,:] == 255)

I want to modify the slice of those locations... Which I can do like this:

raster[:,mask[0],mask[1]] = 0

Is there a more pythonic way... or is this the best bet?

AAmes
  • 333
  • 1
  • 2
  • 11

1 Answers1

3

I would use the mask directly, e.g.

raster[:, raster[0] == 255] = 0

which should be the equivalent of what you wrote.

jakevdp
  • 77,104
  • 11
  • 125
  • 160