votes up 1

Currently limited to atmost 2D array.

Package:
numpy
github stars 18118
Exception Class:
NotImplementedError

Raise code

""" 
    >>> np.ma.notmasked_contiguous(ma, axis=1)
    [[slice(0, 1, None), slice(2, 4, None)], [slice(3, 4, None)], [slice(0, 1, None), slice(3, 4, None)]]

    """
    a = asarray(a)
    nd = a.ndim
    if nd > 2:
        raise NotImplementedError("Currently limited to atmost 2D array.")
    if axis is None or nd == 1:
        return flatnotmasked_contiguous(a)
    #
    result = []
    #
    other = (axis + 1) % 2
    idx = [0, 0]
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 2 votes down

Summary: The notmasked_contiguous function in the numpy.ma module Only accepts 2-D arrays at most as pointed out in the documentation of the definition of the function.

Code to reproduce the error:

import numpy as np
from numpy.ma.extras import masked_array,notmasked_contiguous


a = np.arange(12).reshape((2,2,3)) # here a is intialized to be 3d numpy array
mask = np.zeros_like(a)
mask[1:, :-1] = 1; mask[0, 1] = 1; mask[-1, 0] = 0
ma = np.ma.array(a, mask=mask)
nma = notmasked_contiguous(ma)
print(ma)
print(nma)

Fixed version of the code:

import numpy as np
from numpy.ma.extras import masked_array,notmasked_contiguous
a = np.arange(12).reshape((2,2,3)) # here dimension of a 3
a = a.reshape((4,3)) # a is reshaped to 2D array
mask = np.zeros_like(a)
mask[1:, :-1] = 1; mask[0, 1] = 1; mask[-1, 0] = 0
ma = np.ma.array(a, mask=mask)
nma = notmasked_contiguous(ma)
print(ma)
print(nma)
May 19, 2021 kellemnegasi answer
kellemnegasi 30.0k

Add a possible fix

Please authorize to post fix