How to extract an array of same dimension as the original array meeting a condition? [duplicate]
问题 This question already has answers here : Numpy array loss of dimension when masking (4 answers) Closed 9 months ago . The question sounds very basic. But when I try to use where or boolean conditions on numpy arrays, it always returns a flattened array. I have the NumPy array P = array([[ 0.49530662, 0.07901 , -0.19012371], [ 0.1421513 , 0.48607405, -0.20315014], [ 0.76467375, 0.16479826, -0.56598029], [ 0.53530718, -0.21166188, -0.08773241]]) I want to extract the array of only negative