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

Why does a dot product of two masked vectors in numpy return an oddly shaped array?

I have the following code: result = np.ma.dot( array1, masked_array2 ) Which gives something like this: masked_array(data = 24.681441709536468, mask = False, fill_value = 1e+20) result.data.shape gives: () I can access the value…
0
votes
0 answers

Memory issues when finding masked median of masked ndarray

I am trying to align 60 images by creating a cube (with larger dimensions than the images; 60x3000x4000) that stores information about each image and how much it is shifted by. I then combine that by finding the masking the cube for any 0 values and…
S95
  • 21
  • 4
0
votes
1 answer

Why are the return types of the numpy sum and mean function behaving differently when fed with a masked array?

Debugging a python package I've come across the following issue: In the pathological case that I feed the numpy mean function with a masked array, the return type is a masked array: >>> import numpy as np >>> import numpy.ma as ma >>>…
momme
  • 141
  • 9
0
votes
1 answer

python - modify part of a masked array inside a function

I need to modify part of a masked array inside a function eg: import numpy.ma as ma arr_2d = ma.masked_all((5,5)) arr_3d = ma.masked_all((5,5,5)) arr_3d[0,1] = 5 def func1(arr, val): arr[:] = val looks simple enough but then... >>>…
fred
  • 243
  • 2
  • 3
0
votes
0 answers

Unmasking list with .filled()

I have a masked list such as: [masked_array(data = [ 0.12963803], mask = False, fill_value = 1e+20), masked_array(data = 0.22379663389345425, mask = False, fill_value = 1e+20), masked_array(data = [ 0.13113253], …
Py-ser
  • 1,860
  • 9
  • 32
  • 58
0
votes
3 answers

python fancy indexing with a boolean masked array

I have a numpy masked array of data: data = masked_array(data = [7 -- 7 1 8 -- 1 1 -- -- 3 -- -- 3 --], mask = [False True False False False True False False True True False True True False True]) I have a flag of a specific…
JoVe
  • 435
  • 2
  • 9
  • 17
0
votes
1 answer

Replace values in masked numpy array not working

I have the foll. masked array in numpy called arr with shape (50, 360, 720): masked_array(data = [[-- -- -- ..., -- -- --] [-- -- -- ..., -- -- --] [-- -- -- ..., -- -- --] ..., [-- -- -- ..., -- -- --] [-- -- -- ..., -- -- --] [-- -- --…
user308827
  • 21,227
  • 87
  • 254
  • 417
0
votes
2 answers

When does advanced indexing on structured masked arrays *really* return a copy?

When I have a structured masked array with boolean indexing, under what conditions do I get a view and when do I get a copy? The documentation says that advanced indexing always returns a copy, but this is not true, since something like X[X>0]=42…
gerrit
  • 24,025
  • 17
  • 97
  • 170
0
votes
2 answers

np.ma.argmax on masked array of unsigned integer dtype returns wrong result in numpy 1.11.0

I stumbled over a strange fact concerning masked unsigned integer arrays and np.ma.argmax. Consider the following array: >>> marr = np.ma.array(np.array([[2,2,2], [3,3,3], [1,1,1]]), mask=False, dtype=np.uint16) >>> marr masked_array(data = [[2 2…
MSeifert
  • 145,886
  • 38
  • 333
  • 352
0
votes
2 answers

Averaging numpy masked array over multiple dimensions

It is possible to compute the average of a numpy array over multiple dimensions, as in eg. my_ndarray.mean(axis=(1,2)). However, it does not seem to work with a masked array: >>> import numpy as np >>> a = np.random.randint(0, 10, (2, 2, 2)) >>>…
Arcturus B
  • 5,181
  • 4
  • 31
  • 51
0
votes
1 answer

How to apply a mask to a DataFrame in Python?

My dataset named ds_f is a 840x57 matrix which contains NaN values. I want to forecast a variable with a linear regression model but when I try to fit the model, I get this message "SVD did not converge": X = ds_f[ds_f.columns[:-1]] y =…
florian
  • 881
  • 2
  • 8
  • 24
0
votes
0 answers

Is there a "maskna" and "skipna" in numpy python

I have been searching the web for NaN in Python Numpy arrays and found some things I cannot reproduce. I am using the Anaconda distribution with numpy.version.version == 1.10.4 from numpy import NA as NA only gets me a "cannot import NA". This NA…
cowiie
  • 1
  • 1
-1
votes
1 answer

What is the best way to initialise a NumPy masked array with an existing mask?

I was expecting to just say something like ma.zeros(my_shape, mask=my_mask, hard_mask=True) (where the mask is the correct shape) but ma.zeros (or ma.ones or ma.empty) rather surprisingly doesn't recognise the mask argument. The simplest I've come…
-2
votes
1 answer

Why some data is missing on a figure when I define the axes? My dataset is a DataArray and some values are masked

I would like to be able to define my axis and not lose information. Currently, I am missing the last data point in both dimensions I defined (see figure). DATA = xr.DataArray(np.random.rand(74,13),dims=('section','lag')) DATA =…
Anne Sophie
  • 117
  • 2
  • 12
-2
votes
1 answer

Equivalent of np.array split for masked array

numpy.ma.split_array does not exist. Consequently, does the following code works as intended if arr is a masked array? np.array_split(arr, multiprocessing.cpu_count()) If not, how should I define a function split_masked_array to achieve similar…
WaterFox
  • 850
  • 6
  • 18
1 2 3
10
11