torch.where — PyTorch 1.10.1 documentation
pytorch.org › docs › stabletorch.where. Return a tensor of elements selected from either x or y, depending on condition. The operation is defined as: The tensors condition, x, y must be broadcastable. Currently valid scalar and tensor combination are 1. Scalar of floating dtype and torch.double 2. Scalar of integral dtype and torch.long 3.
python - Conditional assignment of tensor values in ...
https://stackoverflow.com/questions/39045797import tensorflow as tf conditionval = 1 init_a = tf.constant ( [1, 2, 3, 1], dtype=tf.int32, name='init_a') a = tf.variable (init_a, dtype=tf.int32, name='a') target = tf.fill (a.get_shape (), conditionval, name='target') init = tf.initialize_all_variables () condition = tf.not_equal (a, target) defaultvalues = tf.zeros (a.get_shape (), …