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]
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

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 31.6k

Add a possible fix

Please authorize to post fix