implementing NaN propagation in NumPy's np.dot when using masked arrays in version 1.24.0
I'm prototyping a solution and I'm stuck on something that should probably be simple... I'm experimenting with I tried several approaches but none seem to work. I am working with unexpected behavior when trying to perform a matrix multiplication using `np.dot` on masked arrays in NumPy version 1.24.0. I have two 2D arrays, one of which contains NaNs and the other is a masked array. My intention is for the NaNs to be ignored during the dot product calculation, but it seems that the presence of NaNs is affecting the result in a way I didn't anticipate. Hereβs a simplified version of what I am trying: ```python import numpy as np # Create a 2D array with NaNs matrix_a = np.array([[1, 2], [3, np.nan]]) # Create a masked array from another 2D array matrix_b = np.ma.masked_array(np.array([[4, 5], [6, 7]]), mask=[[0, 1], [0, 0]]) # Attempt to perform dot product result = np.dot(matrix_a, matrix_b) print(result) ``` I expected `result` to ignore the second column of `matrix_b` where the mask is applied, but I am getting a result that includes NaN propagation instead. The output is: ``` [[ 4. 10.] [18. nan]] ``` As you can see, the second row contains `nan` instead of the expected numerical result. I also tried using `np.nanmean()` to pre-process `matrix_a`, but that didn't work either because it would remove the NaNs entirely, which isn't what I want. Iβve also considered checking the masked elements before the dot product, but that seems cumbersome. Am I missing something in my approach, or is this a known limitation with `np.dot` and masked arrays? Any insights or workarounds would be greatly appreciated! Any help would be greatly appreciated! My team is using Python for this service. Any ideas how to fix this? Is there a simpler solution I'm overlooking? This is happening in both development and production on Windows 11. Has anyone else encountered this?