where(condition, [x, y], /)
Some inconsistencies with the Dask version may exist.
Return elements chosen from x
or y
depending on :None:None:`condition`
.
When only :None:None:`condition`
is provided, this function is a shorthand for np.asarray(condition).nonzero()
. Using :None:None:`nonzero`
directly should be preferred, as it behaves correctly for subclasses. The rest of this documentation covers only the case where all three arguments are provided.
If all the arrays are 1-D, where
is equivalent to:
[xv if c else yv for c, xv, yv in zip(condition, x, y)]
Values from which to choose. x
, y
and :None:None:`condition`
need to be broadcastable to some shape.
An array with elements from x
where :None:None:`condition`
is True, and elements from y
elsewhere.
This docstring was copied from numpy.where.
nonzero
The function that is called when x and y are omitted
>>> a = np.arange(10) # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... a # doctest: +SKIP array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.where(a < 5, a, 10*a) # doctest: +SKIP array([ 0, 1, 2, 3, 4, 50, 60, 70, 80, 90])
This can be used on multidimensional arrays too:
This example is valid syntax, but we were not able to check execution>>> np.where([[True, False], [True, True]], # doctest: +SKIP
... [[1, 2], [3, 4]],
... [[9, 8], [7, 6]]) array([[1, 8], [3, 4]])
The shapes of x, y, and the condition are broadcast together:
This example is valid syntax, but we were not able to check execution>>> x, y = np.ogrid[:3, :4] # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... np.where(x < y, x, 10 + y) # both x and 10+y are broadcast # doctest: +SKIP array([[10, 0, 0, 0], [10, 11, 1, 1], [10, 11, 12, 2]])
>>> a = np.array([[0, 1, 2], # doctest: +SKIPSee :
... [0, 2, 4],
... [0, 3, 6]])
... np.where(a < 4, a, -1) # -1 is broadcast # doctest: +SKIP array([[ 0, 1, 2], [ 0, 2, -1], [ 0, 3, -1]])
The following pages refer to to this document either explicitly or contain code examples using this.
dask.array.routines.piecewise
dask.array.routines.where
dask.array.routines.select
dask.array.routines.argwhere
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them