Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8819285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:19:05+00:00 2026-06-14T05:19:05+00:00

I create a numpy masked array with the shrink-option set to False (which should

  • 0

I create a numpy masked array with the shrink-option set to False (which should yield a full-sized mask), and then I check the size of the mask:

import numpy as np
import numpy.ma as ma
x = ma.array(range(10),shrink=False)
print 'mask size = ', np.array(x.mask).size

which yields: mask size = 1, i.e., the mask is still the default (shrunk) scalar mask.

Is this a (known) bug?

Update:
It seems that also the option shrink=True does not work properly:

x = ma.array(range(3), mask=True, shrink=True)
x.__setmask__(ma.nomask)                    # remove the mask (should shrink now)
x.mask.size                                 # returns 3, so mask has not shrunk!
_ = x.shrink_mask()                         # enforce shrinking
x.mask.size                                 # returns 1, so only now it's OK 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:19:06+00:00Added an answer on June 14, 2026 at 5:19 am

    There’s a misunderstanding here: the shrink option flag prevents the compression of the mask in operations, not at creation. To get an explicit mask (as a boolean array full of False), use the mask=False flag at creation instead.
    Nevertheless, I agree it should be considered a bug. Nice catch.


    When no explicit mask is given, the default is nomask, a special value corresponding to np.bool_(0): it’s a numpy boolean scalar with a value of False, and like any numpy scalar, a shape of () and a size of 1.

    Note the difference between mask=False and mask=nomask: mask=False will create a mask as a ndarray with the same shape as the data but full of False (that’s a shortcut), while mask=nomask just tell np.ma that the mask is not set (which speeds up computations).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a numpy 2D array which represents a binary mask of
In Numpy, how do I create an array of indices which can be used
I have to create a 2D numpy array from the values x, y from
I'm using numpy to create a cube array with sides of length 100, thus
I have a numpy array like this: x = np.array([[1,2,3],[4,5,6],[7,8,9]]) I need to create
How can I create a huge numpy array using pytables. I tried this but
I want to create an array in numpy that contains the values of a
I would like to create a two dimensional numpy array of arrays that has
I would like to create a function that returns a numpy array if one
I want to create a MATLAB-like cell array in Numpy. How can I accomplish

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.