Questions tagged [masked-array]

Masked arrays are NumPy arrays that may have missing or invalid entries. The `numpy.ma` module provides a nearly work-alike replacement for NumPy that supports data arrays with masks.

151 questions
0
votes
1 answer

Can you assign only unmasked values using numpy.ma?

Is there a way to copy values from one numpy masked array to another where ONLY the unmasked values are copied and the target values are left unchanged for masked source values? It seems like this should be handled automatically, but so far I…
Justin Olbrantz
  • 647
  • 3
  • 11
0
votes
1 answer

How to extarct the mask from a Dask masked array?

In Dask, there is a class called MaskedArray, corresponding to the NumPy class with the same name. The NumPy class has the methods getdata and getmask, which it seems like the Dask class is also supposed to have; however, I can only find a mention…
HelloGoodbye
  • 3,624
  • 8
  • 42
  • 57
0
votes
1 answer

How to randomly sample pairs of elements from a masked numpy array until the exhaustion of elements without any repetition?

I have an array of integers/indices (i.e. arr_F_idx = np.arange(0,200)) and I would like to draw 100 pairs without repetition. I am using a masked array (I transform arr_F_idx after the first draw, as shown in the code below), but it seems that…
Hmn
  • 9
  • 2
0
votes
1 answer

Mask specific values in column after reading csv file

I'm having trouble finding the correct way to mask specific values from a column after reading a csv file. I found how to create a masked array after creating an array directly in the code. If I'm reading a file with data = np.genfromtxt("file") and…
0
votes
1 answer

Masked Array - Count the value in a specific interval

I am quite new to masked arrays and satellite data. I am trying to figure out how to count the number of elements in a masked_array that are in between an interval e.g. say 40 to 80. This is what I have: This is the summary of my masked array…
Filippo Sebastio
  • 1,112
  • 1
  • 12
  • 23
0
votes
0 answers

Finding the average of data storage in a list of masked array

I need to take an average of a bunch of data in different netcdf files, that contain the following dimensions: TOTAL(TSTEP, LAY, ROW, COL) TSTEP is the number of days in a year. So basically i took the average of the data in a year and for each…
0
votes
1 answer

Edit masked array including masked entries

I have a numpy-masked array, where some entries are masked. At some point in my code I want to apply some scaling to the array. I.e. all the values, including the masked ones, have to change according to the operation. E.g.: a =…
dba
  • 325
  • 1
  • 6
  • 16
0
votes
1 answer

numpy: why don't my arrays have the same size after applying a mask intersection?

When I run .compressed() to turn a MaskedArray into a normal ndarray there are two fewer items. Any ideas why this could be? mask_intersection = np.ma.mask_or(p_data.astype("float64"), cr_data.astype("float64")) ipdb> mask_intersection.shape (178,…
jaksco
  • 423
  • 7
  • 18
0
votes
2 answers

Why is matplotlib plotting nan differently than zeros?

I have 2D numpy array that I want to mask and plot. I have tried this. import numpy as np import matplotlib.pyplot as plt a = np.random.random((101,99)) data1 = a.copy() bound = np.percentile(data1, 80) data1[data1
T Walker
  • 330
  • 1
  • 3
  • 12
0
votes
1 answer

Numpy masked array - find segment nearest to specific index

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…
vlro
  • 43
  • 6
0
votes
1 answer

Moving averages without using masked values

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…
0
votes
1 answer

Python 2d interpolation for masked or unordered input data

The data that I have is the frequency (f) and theta *(th) *which are coordinates that correspond to a 2d object beam (b). i.e: (f_i, th_i) == b_ii. I set up the 2d interpolation using scipy.interpolate.interp2d. Works well, until I use new input…
B.Eng
  • 23
  • 4
0
votes
0 answers

how to solve object has no attribute 'strftime'

I've tried to strftime, but i have AttributeError Here is the code dater=num2date(datafile.variables['lightning_flash_TAI93_time'][:], start_value_units.units) daty=dater.strftime("%Y%m%d") date = np.concatenate([date,…
user14735672
0
votes
1 answer

np.median error on array of masked array ValueError:The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I want to compute the median of an array of masked array. No problem to compute the mean but an error rising when I want to compute the median and I don't know why: ValueError: The truth value of an array with more than one element is ambiguous. Use…
Julien Drevon
  • 322
  • 2
  • 17
0
votes
1 answer

numpy genfromtxt - missing data vs bad data

I'm using numpy genfromtxt, and I need to identify both missing data and bad data. Depending on user input, I may want to drop bad value or raise error. Essentially, I want to treat missing and bad data as the same thing. Say I have a file like…
user3240688
  • 1,188
  • 3
  • 13
  • 34