会根据condition的不同返回x或y,当满足条件是返回x,否则返回y。
p.s. x和y都是tensor形式。
========分割线========
以下内容摘自Pytorch官方文档:
NOTE
(1)The tensors condition
, x
, y
must be broadcastable.
(2)Currently valid scalar and tensor combination are 1. Scalar of floating dtype and torch.double 2. Scalar of integral dtype and torch.long 3. Scalar of complex dtype and torch.complex128
Parameters
-
condition (BoolTensor) – When True (nonzero), yield x, otherwise yield y
-
x (Tensor or Scalar) – value (if
x
is a scalar) or values selected at indices wherecondition
isTrue
-
y (Tensor or Scalar) – value (if
y
is a scalar) or values selected at indices wherecondition
isFalse
Returns:A tensor of shape equal to the broadcasted shape of condition
, x
, y