chainer.functions.where

chainer.functions.where(condition, x, y)[source]

Choose elements depending on condition.

This function choose values depending on a given condition. All condition, x, and y must have the same shape.

Parameters:
Returns:

Variable containing chosen values.

Return type:

Variable

Example

>>> cond = np.array([[1, 0], [0, 1]], dtype=np.bool)
>>> cond
array([[ True, False],
       [False,  True]], dtype=bool)
>>> x = np.array([[1, 2], [3, 4]], 'f')
>>> y = np.zeros((2, 2), 'f')
>>> F.where(cond, x, y).data
array([[ 1.,  0.],
       [ 0.,  4.]], dtype=float32)