Strange behavior with np.where and multi-dimensional boolean indexing in NumPy 1.25
I'm trying to implement I'm working with an unexpected result when using `np.where` with a multi-dimensional boolean array in NumPy 1.25... I want to extract elements from a 3D array based on a condition applied to one of its axes. However, the output doesn't match my expectations. Here's the code snippet I'm working with: ```python import numpy as np # Create a 3D array arr = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) # Condition: Extract elements greater than 5 along the last axis condition = arr > 5 # Use np.where to get indices indices = np.where(condition) # Extracting values extracted_values = arr[indices] print("Extracted Values:", extracted_values) ``` When I run this, I get: ``` Extracted Values: [ 6 7 8 9 10 11 12] ``` This is okay, but I expected to see the original indices from `arr` that met the condition since I want to do something with those indices later. Is there a way to directly get the indices that correspond to values meeting the condition instead of just the extracted values? Also, if I try to reshape the output of `np.where`, I get a shape mismatch behavior: `ValueError: want to reshape array of size X into shape (Y,)`. Could someone clarify how I should properly handle this? Any advice on best practices for multi-dimensional indexing with `np.where` would be greatly appreciated! Any advice would be much appreciated. Has anyone dealt with something similar?