Unexpected results when using np.where with multidimensional arrays in NumPy 1.24
Could someone explain I'm optimizing some code but I've been working on this all day and Hey everyone, I'm running into an issue that's driving me crazy..... I'm experiencing unexpected behavior when using `np.where` with a 2D array in NumPy 1.24. My goal is to replace all values in an array that are greater than a certain threshold with a specific value. However, the output doesn't seem to match my expectations. Hereβs a simplified version of my code: ```python import numpy as np array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) threshold = 5 new_value = -1 result = np.where(array > threshold, new_value, array) print(result) ``` I expect the output to replace values greater than 5 with -1, resulting in: ``` [[ 1 2 3] [-1 -1 -1] [-1 -1 -1]] ``` Instead, I am getting: ``` [[ 1 2 3] [ 4 5 6] [ 7 8 9]] ``` I double-checked the condition and the array values, and everything seems fine. I also tried using the `np.clip` function to limit the values before applying `np.where`, but that didn't help either. It seems like `np.where` is not evaluating the condition as I expected. Is there something I might be missing in the usage of `np.where` with multidimensional arrays? Any insights would be appreciated! Thanks in advance!