mask

Numpy mask from cylinder coordinates

Numpy mask from cylinder coordinates Question: I generated the coordinates of a cylinder. Its two faces connect two arbitrary points already given. Is it possible to build a 3D numpy mask of the filled cylinder from the coordinates with standard Python libraries? Creating a 2D mask seems simple enough, but I’m encountering some difficulties with …

Total answers: 1

Mask an array by the index given from other array

Mask an array by the index given from other array Question: I have the following arrays: a = [10, 31, 30, 11, 17, 12, 22, 25, 85, 17, 21, 43] b = [0, 1, 4, 6] I want to mask a based on the index given by array b. That means getting: c = [True, …

Total answers: 5

How to properly mask a numpy 2D array?

How to properly mask a numpy 2D array? Question: Say I have a two dimensional array of coordinates that looks something like x = array([[1,2],[2,3],[3,4]]) Previously in my work so far, I generated a mask that ends up looking something like mask = [False,False,True] When I try to use this mask on the 2D coordinate …

Total answers: 6

Update row values where certain condition is met in pandas

Update row values where certain condition is met in pandas Question: Say I have the following dataframe: What is the most efficient way to update the values of the columns feat and another_feat where the stream is number 2? Is this it? for index, row in df.iterrows(): if df1.loc[index,’stream’] == 2: # do something How …

Total answers: 3

How can you turn an index array into a mask array in Numpy?

How can you turn an index array into a mask array in Numpy? Question: Is it possible to convert an array of indices to an array of ones and zeros, given the range? i.e. [2,3] -> [0, 0, 1, 1, 0], in range of 5 I’m trying to automate something like this: >>> index_array = …

Total answers: 4

Masking multiple columns on a pandas dataframe in Python

Masking multiple columns on a pandas dataframe in Python Question: I am looking to apply multiply masks on each column of a pandas dataset (respectively to its properties) in Python. In the next step, I want to find (a) row(s) in the dataframe that fits all conditions. Therefore I have: df Out[27]: DE FL GA …

Total answers: 2

OpenCV – Apply mask to a color image

OpenCV – Apply mask to a color image Question: How can I apply mask to a color image in latest python binding (cv2)? In previous python binding the simplest way was to use cv.Copy e.g. cv.Copy(dst, src, mask) But this function is not available in cv2 binding. Is there any workaround without using boilerplate code? …

Total answers: 5

How to apply a disc shaped mask to a NumPy array?

How to apply a disc shaped mask to a NumPy array? Question: I have an array like this: >>> np.ones((8,8)) array([[ 1., 1., 1., 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1., 1., 1., …

Total answers: 7