np.meshgrid generates unexpected output shapes when using non-finite values
I'm relatively new to this, so bear with me. I'm experimenting with I'm converting an old project and Hey everyone, I'm running into an issue that's driving me crazy..... I'm sure I'm missing something obvious here, but I'm working on a project and hit a roadblock. I'm working with NumPy version 1.22.0 and trying to create a meshgrid from two arrays that contain some non-finite values (NaNs and Infs)... However, the output shapes of the meshgrid are not what I expected. I have the following code: ```python import numpy as np x = np.array([0, 1, 2, np.nan]) y = np.array([0, np.inf, 3]) X, Y = np.meshgrid(x, y) print(X.shape, Y.shape) print(X) print(Y) ``` I expected the shapes of `X` and `Y` to be (len(y), len(x)), which should be (3, 4) in this case since there are 3 elements in `y` and 4 in `x`. However, I'm getting the following output: ``` (3, 4) [[ 0. 1. 2. nan] [ 0. 1. 2. nan] [ 0. 1. 2. nan]] [[ 0. inf 3.] [ 0. inf 3.] [ 0. inf 3.]] ``` It seems like the presence of NaN in `x` is causing unexpected behavior. The meshgrid function does not seem to handle non-finite values gracefully, leading to a situation where the shapes match, but the actual contents of `X` and `Y` are not aligned as I anticipated. I also tried using `np.nan_to_num` to replace NaNs: ```python x_clean = np.nan_to_num(x) X, Y = np.meshgrid(x_clean, y) ``` But this did not resolve the scenario as the replacement alters the original values. Is there a way to properly handle non-finite values when generating a meshgrid without losing the integrity of my data? Any insights or workarounds would be greatly appreciated! For context: I'm using Python on Windows. This is part of a larger CLI tool I'm building. Has anyone else encountered this? I'm working on a web app that needs to handle this. How would you solve this? I'm open to any suggestions. I'm working on a desktop app that needs to handle this. I'd really appreciate any guidance on this. Could someone point me to the right documentation? I'm working with Python in a Docker container on Linux. What am I doing wrong?