8000 Cannot perform reduce on the masks of structured or masked arrays with flexible type · Issue #7492 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Cannot perform reduce on the masks of structured or masked arrays with flexible type #7492
Closed
@hsintone

Description

@hsintone

If we have a structured/record/masked array with variable types:

In [1]: import numpy as np, numpy.lib.recfunctions as nrf 
In [2]: me = nrf.merge_arrays((np.array([1, 2]), np.array([10., 20., 30.])), usemask=True)
In [3]: me
Out[3]:
masked_array(data = [(1, 10.0) (2, 20.0) (--, 30.0)],
             mask = [(False, False) (False, False) (True, False)],
       fill_value = (999999, 1e+20),
            dtype = [('f0', '<i8'), ('f1', '<f8')])

we cannot run reduce based functions on it:

In [4]: np.any(me)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
...
TypeError: cannot perform reduce with flexible type

Ok, this is fine. But mask has a lot more predictable content despite the data type or the type of the array, yet we still get the same error:

In [5]: me.mask
Out[5]: 
array([(False, False), (False, False), (True, False)],
      dtype=[('f0', '?'), ('f1', '?')]) 

In [6]: np.any(me.mask)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
...
TypeError: cannot perform reduce with flexible type

Could numpy be changed to allow it to perform reduce on the masks of these arrays? Here's the above as a copypasteable snippet:

import numpy as np, numpy.lib.recfunctions as nrf 
me = nrf.merge_arrays((np.array([1, 2]), np.array([10., 20., 30.])), usemask=True)
np.any(me) # should not work
np.any(me.mask) # maybe possibly could work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0