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
1
vote
2 answers

numpy 2d: How to get the index of the max element in the first column for only the allowed value in the second column

Help find a high-performance way to solve the problem: I have a result after neural-network(answers_weight), a category for answers(same len) and allowed categories for current request: answers_weight = np.asarray([0.9, 3.8, 3, 0.6, 0.7, 0.99]) #…
Ssb
  • 23
  • 3
1
vote
2 answers

Writing an efficient code for applying a reverse operation using masks in NumPy

Firstly, I have a compressed numpy array c and a mask m that was used to generate c from a full array a. I want to output a reconstructed array b of the same shape as the original array a, but with the results from the compressed array. The…
Tania
  • 418
  • 3
  • 20
1
vote
1 answer

How can I combine masks of two 3D arrays and apply it to a separate 3D array?

I've two 3D masked arrays of shape (4880,129,135). Let's assume the arrays are A and B with masks m1 and m2 containing boolean values for the respective arrays. I need to create a new mask m3 which contains True for True values in m1 and m2 and…
anish
  • 13
  • 4
1
vote
3 answers

Python: fitting curve to masked data with scipy curve_fit

I'm trying to write a script with python/numpy/scipy for data manipulation, fitting and plotting of angle dependent magnetoresistance measurements. I'm new to Python, got the frame code from my PhD advisor, and managed to add few hundred lines of…
krdzi
  • 11
  • 2
1
vote
0 answers

Replacing masked data with previous values of same dataset

I am working on filling in missing data in a large (4GB) netcdf datafile (3 dimensions: time, longitude and latitude). The method is to fill in the masked values in data1 either with: 1) previous values from data1 or 2) with data from another…
Idalh
  • 31
  • 3
1
vote
1 answer

How to get the last non-zero value of NumPy masked array?

I am working on a model. The results are stored in a NetCFD file with masked data of lon, lat and time per particle. I want to get the last real value of lon, lat, time for each particle. I have managed to get the position of the last real number,…
Emma
  • 11
  • 2
1
vote
1 answer

Loop over clump_masked indices

I have an array y_filtered that contains some masked values. I want to replace these values by some value I calculate based on their neighbouring values. I can get the indices of the masked values by using masked_slices =…
MTV DNA
  • 187
  • 7
1
vote
1 answer

Calculate mean, variance, covariance of different length matrices in a split list

I have an array of 5 values, consisting of 4 values and one index. I sort and split the array along the index. This leads me to splits of matrices with different lengths. From here on I want to calculate the mean, variance of the fourth values and…
chron0x
  • 875
  • 9
  • 19
1
vote
2 answers

Deleting elements from a list if that value is masked in another list

I have imported data that has the format of a numpy masked array of incrementing integers. The masked elements are irregular and not repeating, e.g printing it yields: masked = [0,1,--,3,--,5,6,--,--,9,--] And I have another list of incrementing…
rh1990
  • 880
  • 7
  • 17
  • 32
1
vote
1 answer

numpy - Change/Specify dtypes of masked array columns

I have a csv-file containing a lot of data that I want to read as a masked array. I've done so using the following: data=np.recfromcsv(filename,case_sensitive=True,usemask=True) which works just fine. However, my problem is that the data are either…
RxHEAD
  • 85
  • 1
  • 8
1
vote
3 answers

How can I efficiently "stretch" present values in an array over absent ones

Where 'absent' can mean either nan or np.masked, whichever is easiest to implement this with. For instance: >>> from numpy import nan >>> do_it([1, nan, nan, 2, nan, 3, nan, nan, 4, 3, nan, 2, nan]) array([1, 1, 1, 2, 2, 3, 3, 3, 4, 3, 3, 2, 2]) #…
Eric
  • 95,302
  • 53
  • 242
  • 374
1
vote
2 answers

Does python dask package support numpy like masked arrays?

Is there a way to use the Python Dask package to mimic a Numpy masked array and do calculations considering the mask, like in Numpy: import numpy as np data = np.array([0, 1, 9999, 2, 1, 0, 9999]) value = 9999 mdata = np.ma.masked_where(data ==…
mastho
  • 11
  • 2
1
vote
1 answer

How to replace a double for-loop with mask and indexing?

I have a couple of nested for-loops that do the right thing (masked copy of array). However the performance is too slow, and I feel there must be a better Pythonic way to do this. The goal is use the mask to determine when to copy data from the…
MJK
  • 13
  • 2
1
vote
1 answer

Plotting masked array that has been gridded using griddata

I have a 2D array of satellite data, and two corresponding 2D arrays giving the latitude and longitude of each pixel. The data array is a masked array. When I plot it up using pcolormesh, it looks like this: m.pcolormesh(lon, lat, data) I am…
hm8
  • 1,381
  • 3
  • 21
  • 41
1
vote
2 answers

Python help using 'numpy.masked_where' conditionally from another list

I am writing an astronomy observation simulation. I have a data array which is 1 measurement per 24 hours: data = [0,1,2,3,4] And I have a array which is the minutes of cloud/rain in a 24 hour period, rounded to the nearest hour: weather =…
rh1990
  • 880
  • 7
  • 17
  • 32