Python Forum
numpy masking/filtering
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numpy masking/filtering
#2
I think you could get something by using numpy's MaskedArray type, something along the line of
import numpy as np
import numpy.ma as ma

N = 10
band = 3
x = np.tile(np.arange(N, dtype=int), (N, 1))
mask = (abs(x-x.T) <= band)

print(mask)
m = np.repeat(mask[:,:,np.newaxis], 3, axis=2)

df = np.zeros((N, N, 3), dtype=np.uint8)
view = ma.masked_array(df, mask=m)
view[:, 0] = 255

print(df)
Reply


Messages In This Thread
numpy masking/filtering - by nilamo - Dec-03-2021, 04:32 AM
RE: numpy masking/filtering - by Gribouillis - Dec-03-2021, 09:06 AM
RE: numpy masking/filtering - by nilamo - Dec-04-2021, 06:04 PM
RE: numpy masking/filtering - by nilamo - Dec-04-2021, 10:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 1,030 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,868 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  Problem with masking precipitation data into a shapefile atrwmb109 0 1,992 Jul-22-2019, 05:10 PM
Last Post: atrwmb109
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 3,138 Apr-09-2019, 04:54 PM
Last Post: PhysChem

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020