ENH: np.reduce should allow broadcasting WHERE
with ARRAY
in either direction
#29152
Labels
WHERE
with ARRAY
in either direction
#29152
Proposed new feature or change:
In
np.reduce
,np.mean
, etc., theWHERE
argument allows for selective reduction of only certain elements. It performs a one-way broadcast ofWHERE
toARRAY:
But sometimes you'd like the broadcast to go in the other direction. For example, suppose you want to compute the average row number in a 2D array where some condition is true:
This raises:
because the broadcast is tried in one direction only (from
WHERE
->ARRAY).
If
ARRAY
would otherwise be a repeated set of values (e.g. a column vector of row indices), it seems sensible to allow broadcasting betweenWHERE
andARRAY
in either direction. In this example,ARRAY
->WHERE
broadcasting would occur. Otherwise, you must waste memory "filling out"ARRAY:
The text was updated successfully, but these errors were encountered: