masking

How to filter 3D array with a 2D mask

How to filter 3D array with a 2D mask Question: I have a (m,n,3) array data and I want to filter its values with a (m,n) mask to receive a (x,3) output array. The code below works, but how can I replace the for loop with a more efficient alternative? import numpy as np data …

Total answers: 1

Creating a long masking list (Python)

Creating a long masking list (Python) Question: Here is what I have: long_list = a very long list of integer values (6M+ entries) wanted_list = a list of integer values that are of interest (70K entries) What I need: mask_list = a list of booleans of the same length as long_list, describing whether each element …

Total answers: 3

Numpy array loses shape after applying mask across axis

Numpy array loses shape after applying mask across axis Question: Problem I have np.array and mask which are of the same shape. Once I apply the mask, the array loses it shape and becomes 1D – flattened one dimensional. Question I am wanting to reduce my array across some axis, based on a mask of …

Total answers: 2

Python: Elegant and efficient ways to mask a list

Python: Elegant and efficient ways to mask a list Question: Example: from __future__ import division import numpy as np n = 8 “””masking lists””” lst = range(n) print lst # the mask (filter) msk = [(el>3) and (el<=6) for el in lst] print msk # use of the mask print [lst[i] for i in xrange(len(lst)) …

Total answers: 6