I have a mask which may have holes inside. I want to erode from the outside of the mask (so not the holes), horizontally in, a certain number of pixels. The trick being if I’m eroding inwards 5px and at a certain point there is a hole 3px in from the edge, I want to erode those 3px and then
Tag: numpy
Calculate the cumulative sum of multiplying each element of one array by all the elements of a second array
I need to efficiently calculate the running sum of multiplying the elements of one array by all the elements of a second array. It is probably easiest to explain what I am trying to do with code: My ‘a’ array will typically be big so I would like this to run as fast as possible, but right now it is
Python object array of empty arrays
I am attempting to create a numpy array of empty arrays without using loops. Using loops, I can use a simplified operation like Or a marginally more sophisticated approach based on np.nditer: I can’t seem to find an indexing expression that will allow me to make this assignment in a vectorized manner. I’ve tried the following: Even np.nditer does not
Numpy multiple min indices 3d array [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 1 year ago. Improve this question I have a numpy array of shape (9, 200, 200). I would like to get a list of the indices of the minimum value for
How to combine rows that have the same values in two columns (Python)?
I currently have a csv file as follows. The first part just shows the columns names. The g column values are the same for every f value. The only unique part is p. Using python, how could I combine this as follows: One thing to note is that the csv file is much larger and that some f values might
Vectorized approach to masking red and blue channels in an image
I am trying to change all the red and blue pixels in an image to black to have only green pixels (based on certain conditions). To do this right now I am using multiple for loops and the process, although it works, is extremely slow. The code I have so far – Is there any way I can vectorize this
Excel like vlookup using python pandas with some conditions
I need to perform vlookup on dataframe using python/pandas like in Excel with some conditions. Condition:- I need to create a one new column (DFM) in my 2nd DataFrame using Excel like vlookup. If DFM value is na then print 100% in 2nd Dataframe’s DFM. Like in below result data. In result data DFM column I need to apply vlookup
Search multi-string in pandas column
I have a pandas dataframe which looks like this: Now I want to search col2 on a given condition and select rows accordingly. For example: Answer You can split values and compare with sets by issubset in Series.map:
Dataframe: shifting values over columns
I have a dataframe with some NaN values in my s_x columns. If NaN values exist in them, I want them to be in the last columns. Example: Given values in the s_x columns of [Nan, 1, Nan, 2] I want the values to shift left over the columns to result in [1, 2, NaN, NaN] Example 2: My current
Broadcasting over two arrays with different shapes (Numpy-Python)
Suppose I have the following arrays: So an array with shape (5, 5) Now I have a second array, which is a slice of the first: An array with shape (2, 5). Now I want to subtract every vector of the first array by the vectors of the second array subsequently(excluding- in the first array- the vector of the second