votes up 1

compress_cols works for 2D arrays only.

Package:
numpy
github stars 18118
Exception Class:
NotImplementedError

Raise code

""" 
    See Also
    --------
    compress_rowcols

    """
    a = asarray(a)
    if a.ndim != 2:
        raise NotImplementedError("compress_cols works for 2D arrays only.")
    return compress_rowcols(a, 1)

def mask_rows(a, axis=np._NoValue):
    """
    Mask rows of a 2D array that contain masked values.

    This function is a shortcut to ``mask_rowcols`` with `axis` equal to 0. """
🙏 Scream for help to Ukraine
Today, 25th May 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 0 votes down

Compress_cols function in the numpy.ma.extras module only works for a 2-D array.

Steps to reproduce the error:

  • Setup the test environment
$ pip install --user pipenv
$ mkdir test_folder
$ cd test_folder
$ pipenv shell
$ pipenv install numpy
  • Run the test code:
import numpy as np
a = np.arange(10)
compressed = np.ma.compress_cols(a)
print(compressed)

Fixed version of the code:

import numpy as np
a = np.arange(10).reshape(2,5)
compressed = np.ma.compress_cols(a)
print(compressed)

May 28, 2021 kellemnegasi answer
kellemnegasi 29.0k

Add a possible fix

Please authorize to post fix