advanced patterns when calculating the mean of a masked array in NumPy 1.22.0
I'm integrating two systems and I'm working with a masked array in NumPy 1.22.0 and working with an scenario when trying to compute the mean of it. My data has some masked values, and I expect the mean calculation to ignore these masked entries. However, the result seems to include them, which is not what I anticipated. Here's a snippet of my code: ```python import numpy as np # Creating a masked array with some masked values data = np.array([1, 2, 3, 4, 5]) masked_data = np.ma.masked_array(data, mask=[0, 0, 1, 0, 1]) # Masking values 3 and 5 # Calculating the mean mean_value = np.ma.mean(masked_data) print('Mean of masked array:', mean_value) ``` When I run this, I get the output: ``` Mean of masked array: 2.5 ``` I expected the mean to be calculated only from the unmasked values (1, 2, and 4). Instead, it seems like it's averaging over the entire array's original size. I've also tried using `np.ma.mean(masked_data, keepdims=True)`, but the result remains the same. Am I missing something in how masked arrays work, or is there a bug in this version of NumPy? Any insights on how to achieve the intended mean calculation would be greatly appreciated! This is for a service running on Debian.