Unexpected results with np.where when filtering elements in a multi-dimensional array
I'm a bit lost with I've spent hours debugging this and I'm trying to debug I'm stuck on something that should probably be simple. I'm working with NumPy version 1.23.0, and I'm encountering unexpected results when using `np.where` to filter elements from a multi-dimensional array. I have a 2D array representing some temperature readings and I want to extract the indices where the values exceed a certain threshold. Here's the code I've been trying: ```python import numpy as np temperature_data = np.array([[22, 25, 19], [30, 15, 28], [35, 40, 18]]) threshold = 20 # Using np.where to find indices indices = np.where(temperature_data > threshold) print(indices) ``` When I run this, I get the output: ``` (array([0, 1, 1, 2, 2]), array([1, 0, 2, 0, 1])) ``` This seems correct in terms of indicating the row and column indices, but when I attempt to use these indices to retrieve the actual values: ```python filtered_values = temperature_data[indices] print(filtered_values) ``` I get output as: ``` [25 30 28 35 40] ``` While this is the expected output, I initially thought it would return a 1D array that maintains the shape of the input array. Instead, I see that the structure of my filtered array is just a flat array of values. My main concern is understanding how `np.where` interacts with indices in this context. Is there a way to get `filtered_values` as a 2D array instead? I've tried reshaping the result with `np.reshape`, but it doesn't seem to work as intended. Any insights on best practices for extracting filtered values while maintaining the dimensionality would be greatly appreciated. What's the best practice here? This is part of a larger CLI tool I'm building. How would you solve this? My development environment is Linux. My team is using Python for this microservice. How would you solve this? I'd be grateful for any help. Cheers for any assistance!