How can I specify some values in a numpy array based on a condition? I don’t understand why I end with 0 instead of zero or empty values, where the condition is not met ... b is a numpy array filled with 0 and 1 values, c is another completely filled numpy array. All arrays 71x71x166
a = np.empty(((71,71,166))) d = np.empty(((71,71,166))) for indexes, value in np.ndenumerate(b): i,j,k = indexes a[i,j,k] = np.where(b[i,j,k] == 1, c[i,j,k], d[i,j,k])
I want to end an array that only has values in which the condition is satisfied, and is empty everywhere, but without changing its shape.
FULL EDITION FOR DEVELOPMENT, as requested:
I start with a float-filled array with the form (71,71,166)
I am creating an int array based on the trim applied to the floating point array, basically creating several bins, roughly allocating 10 areas inside the array with 0 values between
I want to end up with an array with a shape (71,71,166), which has average values in a certain direction of the array (assuming the vertical direction, if you think of a three-dimensional array as a 3D cube) of a certain "bin", .. .
so I tried to skip the “bunkers” b == 1, b == 2, etc., sampling the float where this condition is met, but zero in another place, so I can take the average value and then recombine into one array in end of loop ...
Not sure what I understood myself. I use np.where and use indexing as I keep getting errors when I try to do this, although this seems very inefficient.