Category : masked-array

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 ..

Read more

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, ..

Read more

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 ..

Read more