I have a series of small images, stored as 2d numpy arrays. After applying a threshold, I turn the input image into a masked array (mask out values below threshold). Based on this, as shown in the plot below I end up with a number of different objects (2 sometimes more). How can I identify ..

#### Category : masked-array

I was trying to understand numpy masks better and decided to try a simple fizzbuzz exercise (since np arrays are homogenous, 9993 is "fizz", 9995 = "buzz", 9998 = "fizzbuzz"). However, I noticed behavior I cannot understand and was hoping that someone could explain. In the first case, I created my masks like that: In: ..

For a one dimensional numpy array of 1’s and 0’s, how can I effectively "mask" the array such that after the occurrence of a 1, the next n elements of the array are converted to zero. After the n elements have passed, the pattern repeats such that the first next occurrence of a 1 is ..

I would like to know if you could give me a way to calculate rolling means on a numpy masked array, without using the masked values. I currently am using the convolve numpy method, but it does not work: import numpy as np a=np.array([1,2,5,4,9,6,1000,3,6,2,9,0]) a=np.ma.masked_where(a>990,a) print(a) a=np.convolve(a, np.ones(5), "valid")/5 print(a) >>>[1 2 5 4 9 ..

I have a numpy masked nd-array. I need to find the median along a specific axis. For some cases, I end up having even number of elements, in which case numpy.ma.median gives average of the middle two elements. However, I don’t want the average. I want one of the median elements. Any one of the ..

I have masked array from which I extracted and converted Datetime from a time series presented in terms of seconds from start date into an ‘Array of an object’. Using the following in python. date=num2date(time, units = data.variables[‘time’].units) when I print date I get Out[41]: masked_array(data=[cftime.DatetimeGregorian(2002, 8, 23, 9, 0, 0, 0, has_year_zero=False), cftime.DatetimeGregorian(2003, 9, ..

The source of this post is from an earlier post. I have X,Y,Z 2D arrays. I only want to see the plot in the first-quadrant where all x, y and z are positive. I use masking on all negative z entries. However it was noticed that scatter plots indeed respect the masking and do not ..

As the title indicates I want to use numpy.argpartition on a masked array. I can, but .argpartition does not honor the mask (it emits a warning message notifying the user as well). This is not useful since the masked data corrupt the results of .argpartition. Any suggestions for replacement methods? I need to know the ..

I have a 3d multi-dimensional numpy array with shape=(5, 5, 5). I mask that array into an "outer" and "inner" sector with a boolean mask and afterwards with np.ma.masked_array . It looks something like this: arr = np.arange(0, 125).reshape((5,5,5)) mask_out = np.array([[[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, ..

The unvectorized code reads: import numpy as np import numpy.ma as ma np.random.seed(42) H = np.random.uniform(0.1, 1.0, size=(6,8)) r, c = H.shape mask = H.max(axis=1) > 0.95 x = np.linspace(0, 10, c) weighted_averages = ma.masked_all((r,), dtype=H.dtype) for i in range(r): if mask[i]: weighted_averages[i] = np.average(x, weights=H[i, :]) Here’s my attempt at vectorizig it: _, xx ..

## Recent Comments