Confusion with np.where yielding unexpected results when applied to a masked array in NumPy 1.24.3
I'm working on a personal project and I've searched everywhere and can't find a clear answer... I'm working with unexpected behavior when using `np.where` with a masked array in NumPy 1.24.3. Specifically, I expected the resulting indices to reflect only the unmasked values, but it seems to include the masked ones as well. Here's a simplified version of what I'm doing: ```python import numpy as np # Create a masked array data = np.array([1, 2, 3, 4, 5]) masked_data = np.ma.masked_array(data, mask=[0, 1, 0, 1, 0]) # Now I want to find indices where values are greater than 2 indices = np.where(masked_data > 2) print(indices) ``` I expected to see indices of `(2, 4)` in the output since only values `3` and `5` are unmasked and greater than `2`. Instead, I get `(array([2, 4]),)`, which seems correct at first glance, but when I try to use these indices to extract values from `masked_data`, I see that the values are still influenced by the mask. If I further extract the values using these indices: ```python extracted_values = masked_data[indices] print(extracted_values) ``` The result is `masked_array(data=[--, 5], mask=[ True, False], fill_value=999999)`, indicating that the presence of the mask is still affecting the output. I'm not sure if I'm misunderstanding how `np.where` interacts with masked arrays, or if this is a bug. I've also tried using `np.ma.where`, but the behavior appears to be the same. Any insights on how to properly handle this situation or if there are better practices would be greatly appreciated! Thanks in advance for your help! For context: I'm using Python on Linux. How would you solve this? I'd really appreciate any guidance on this.