8000 IndexError with np.ma.median along axis on unmasked array · Issue #8015 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
IndexError with np.ma.median along axis on unmasked array #8015
Closed
@MSeifert04

Description

@MSeifert04

Something has changed between numpy 1.11 and the master branch, and it seems np.ma.median cannot handle an unmasked (mask=False) MaskedArray.

For example: np.ma.median(np.ma.array(np.ones((5, 5))), axis=0) throws an IndexError.

I haven't investigated it but to me it seems that np.ma.array creates a new mask (if the array hasn't got a mask already) and it is False (scalar). When using an axis with np.ma.median I suspect that the mask is applied to the data and then throws this Error:

IndexError                                Traceback (most recent call last)
<ipython-input-26-b5117c1f3918> in <module>()
----> 1 np.ma.median(np.ma.array(np.ones((5, 5))), axis=0)

C:\-\lib\site-packages\numpy\ma\extras.py in median(a, axis, out, overwrite_input, keepdims)
    693 
    694     r, k = _ureduce(a, func=_median, axis=axis, out=out,
--> 695                     overwrite_input=overwrite_input)
    696     if keepdims:
    697         return r.reshape(k)

C:\-\lib\site-packages\numpy\lib\function_base.py in _ureduce(a, func, **kwargs)
   3631         keepdim = [1] * a.ndim
   3632 
-> 3633     r = func(a, **kwargs)
   3634     return r, keepdim
   3635 

C:\-\lib\site-packages\numpy\ma\extras.py in _median(a, axis, out, overwrite_input)
    736             low = high
    737     else:
--> 738         low[odd] = high[odd]
    739 
    740     if np.issubdtype(asorted.dtype, np.inexact):

C:\-\lib\site-packages\numpy\ma\core.py in __getitem__(self, indx)
   3161 
   3162         """
-> 3163         dout = self.data[indx]
   3164         # We could directly use ndarray.__getitem__ on self.
   3165         # But then we would have to modify __array_finalize__ to prevent the

IndexError: in the future, 0-d boolean arrays will be interpreted as a valid boolean index

Which currently breaks some tests for astropy (see astropy/astropy#5303).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0