Tensor

class dragon.vm.torch.Tensor(
  *args,
  **kwargs
)[source]

A multi-dimensional array containing elements of a single data type.

To create a tensor from constant value, use torch.tensor(...):

# Create a constant tensor
# The value is 1, dimensions is (0,)
const_tensor = torch.tensor(1, dtype='float32')

Besides, following initializers can also be used:

# Create an empty float32 tensor
# The dimensions is (1, 2)
empty_tensor = torch.empty(1, 2, dtype='float32')

# Create a float32 tensor filling ``one`` or ``zero``
ones = torch.ones(1, 2, dtype='float32')
zeros = torch.zeros(1, 2, dtype='float32)

Construct a tensor with device and grad will sometimes be helpful:

# Initialize a weight and bias on the gpu:0, whose gradient should not be ignored
weight = torch.ones(1, 2, device=torch.device('cuda', 0), requires_grad=True)
bias = torch.tensor(0, device=torch.device('cuda', 0), requires_grad=True)

Be careful to store a tensor object, or the memory will not be free:

# The memory of ``my_tensor`` will be held
# until the reference count decrease to zero
my_object.tensors = []
my_object.tensors.append(my_tensor)

Properties

data

Tensor.data

Return a data reference detaching the grad.

Returns:
dragon.vm.torch.Tensor – The data tensor.

dtype

Tensor.dtype

Return the data type.

Returns:
str – The data type.

device

Tensor.device

Return the device of this tensor.

Returns:
dragon.vm.torch.device – The device.

grad

Tensor.grad

Return a grad reference if gradient had be computed.

Returns:
dragon.vm.torch.Tensor – The grad tensor.

id

Tensor.id

Return the tensor identity.

Returns:
str – The identity.

requires_grad

Tensor.requires_grad

Return a bool report whether the grad is required.

Returns:
boolTrue if requiring grad otherwise False.

shape

Tensor.shape

Return the shape of this tensor.

Returns:
dragon.vm.torch.Size – The shape.

Methods

abs

Tensor.abs()

Return a tensor with the absolute value.

\[\text{out} = \left| \text{self} \right| \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.abs(…) : Compute the absolute value of input.

add

Tensor.add(value)

Compute the element-wise addition.

\[\text{out} = \text{self} + \text{value} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.add(…) : Compute the element-wise addition.

add_

Tensor.add_(value)

Compute the element-wise addition.

\[\text{self} \mathrel{+}= \text{value} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The self.

See also

torch.add(…) : Compute the element-wise addition.

backward

Tensor.backward(gradient=None)

bitwise_not

Tensor.bitwise_not()

Compute the element-wise NOT bitwise operation.

\[\text{out} = \,\,\sim \text{self} \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.bitwise_not(…) : Compute the element-wise NOT bitwise operation.

bitwise_not_

Tensor.bitwise_not_()

Compute the element-wise NOT bitwise operation.

\[\text{self} = \,\,\sim \text{self} \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.bitwise_not(…) : Compute the element-wise NOT bitwise operation.

bitwise_xor

Tensor.bitwise_xor(other)

Compute the element-wise XOR bitwise operation.

\[\text{out} = \text{self} \oplus \text{other} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.bitwise_xor(…) : Compute the element-wise XOR bitwise operation.

bitwise_xor_

Tensor.bitwise_xor_(other)

Compute the element-wise XOR bitwise operation.

\[\text{self} = \text{self} \oplus \text{other} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The self.

See also

torch.bitwise_xor(…) : Compute the element-wise XOR bitwise operation.

bool

Tensor.bool()

Return a bool tensor with the same data.

Returns:
dragon.vm.torch.Tensor – The output tensor.

bool_

Tensor.bool_()

Cast to a bool tensor.

Returns:
dragon.vm.torch.Tensor – The self.

byte

Tensor.byte()

Return an uint8 tensor with the same data.

Returns:
dragon.vm.torch.Tensor – The output tensor.

byte_

Tensor.byte_()

Cast to an uint8 tensor.

Returns:
dragon.vm.torch.Tensor – The self.

ceil

Tensor.ceil()

Return a tensor taken the ceil of elements.

\[\text{out} = \lceil \text{self} \rceil \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.ceil(…) : Compute the smallest integer not less than input.

ceil_

Tensor.ceil_()

Set to the ceil of elements.

\[\text{self} = \lceil \text{self} \rceil \]
Returns:
dragon.vm.torch.Tensor – The self.

See also

torch.ceil(…) : Compute the smallest integer not less than input.

char

Tensor.char()

Return an int8 tensor with the same data.

Returns:
dragon.vm.torch.Tensor – The output tensor.

char_

Tensor.char_()

Cast to an int8 tensor.

Returns:
dragon.vm.torch.Tensor – The self.

chunk

Tensor.chunk(
  chunks,
  dim=0
)

Split self into several parts along the given dim.

Parameters:
  • chunks (int) – The number of chunks to split.
  • dim (int, optional, default=0) – The dim to split.
Returns:

Sequence[dragon.vm.torch.Tensor] – The output chunks.

clamp

Tensor.clamp(
  min=None,
  max=None
)

Return a tensor with elements clamped into a range.

Parameters:
  • min (number, optional) – The min value.
  • max (number, optional) – The max value.
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.clamp(…) : Compute the clipped input according to the given bounds.

clamp_

Tensor.clamp_(
  min=None,
  max=None
)

Clamp elements into the a range.

Parameters:
  • min (number, optional) – The min value.
  • max (number, optional) – The max value.
Returns:

dragon.vm.torch.Tensor – The self.

See also

torch.clamp(…) : Compute the clipped input according to the given bounds.

copy_

Tensor.copy_(src)[source]

Copy the elements into this tensor.

Parameters:
Returns:

dragon.vm.torch.Tensor – The self.

cos

Tensor.cos()

Compute the cos.

\[\text{out} = \cos(\text{self}) \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.cos(…) : Compute the cos of input.

cpu

Tensor.cpu()[source]

Switch the internal storage on cpu memory.

Returns:
dragon.vm.torch.Tensor – The self.

cuda

Tensor.cuda(device=None)[source]

Switch the internal storage on cuda memory.

Parameters:
  • device (int, optional) – The device index.
Returns:

dragon.vm.torch.Tensor – The self.

cumsum

Tensor.cumsum(dim)

Return a tensor with the cumulative sum of elements.

Parameters:
  • dim (int) – The cumulative dimension.
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.cumsum(…) : Compute the cumulative sum of elements along the given axis.

detach

Tensor.detach()[source]

Return a data reference detaching the grad.

Returns:
dragon.vm.torch.Tensor – The data tensor.

dim

Tensor.dim()[source]

Return the number of dimensions.

Returns:
int – The number of dimensions.

div

Tensor.div(value)

Compute the element-wise division.

\[\text{out} = \text{self} \div \text{value} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.div(…) : Compute the element-wise division.

div_

Tensor.div_(value)

Compute the element-wise division.

\[\text{self} \mathrel{\div}= \text{value} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The self.

See also

torch.div(…) : Compute the element-wise division.

double

Tensor.double()

Return a float64 tensor with the same data.

Returns:
dragon.vm.torch.Tensor – The output tensor.

double_

Tensor.double_()

Cast to a float64 tensor.

Returns:
dragon.vm.torch.Tensor – The self.

eq

Tensor.eq(other)

Compute the element-wise equal comparison.

\[\text{out} = (\text{self} = \text{other}) \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.eq(…) : Compute the element-wise equal comparison.

exp

Tensor.exp()

Compute the exponential.

\[\text{out} = \exp{\text{self}} \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.exp(…) : Compute the exponential of input.

expand

Tensor.expand(*sizes)

Return a tensor with elements broadcast.

Parameters:
  • sizes (int...) – The output dimensions to broadcast to.
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.expand(…) : Broadcast input according to given sizes.

expand_as

Tensor.expand_as(other)[source]

Return a tensor with elements broadcast like another.

Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.expand(…) : Broadcast input according to given sizes.

fill_

Tensor.fill_(value)

Fill with the given constant value.

\[\text{self} \leftarrow \text{value} \]
Parameters:
  • value (number) – The constant value.
Returns:

dragon.vm.torch.Tensor – The self.

float

Tensor.float()

Return a float32 tensor with the same data.

Returns:
dragon.vm.torch.Tensor – The output tensor.

float_

Tensor.float_()

Cast to a float32 tensor.

Returns:
dragon.vm.torch.Tensor – The self.

floor

Tensor.floor()

Return a tensor taken the floor of elements.

\[\text{out} = \lfloor \text{self} \rfloor \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.floor(…) : Compute the largest integer not greater than input.

floor_

Tensor.floor_()

Set to the floor of elements.

\[\text{self} = \lfloor \text{self} \rfloor \]
Returns:
dragon.vm.torch.Tensor – The self.

See also

torch.floor(…) : Compute the largest integer not greater than input.

ge

Tensor.ge(other)

Compute the element-wise greater-equal comparison.

\[\text{out} = (\text{self} \geq \text{other}) \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.ge(…) : Compute the element-wise greater-equal comparison.

gt

Tensor.gt(other)

Compute the element-wise greater comparison.

\[\text{out} = (\text{self} > \text{other}) \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.gt(…) : Compute the element-wise greater comparison.

half

Tensor.half()

Return a float16 tensor with the same data.

Returns:
dragon.vm.torch.Tensor – The output tensor.

half_

Tensor.half_()

Cast to a float16 tensor.

Returns:
dragon.vm.torch.Tensor – The self.

index_select

Tensor.index_select(
  dim,
  index
)

Select the elements along the dim dim using index.

Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

int

Tensor.int()

Return an int32 tensor with the same data.

Returns:
dragon.vm.torch.Tensor – The output tensor.

int_

Tensor.int_()

Cast to an int32 tensor.

Returns:
dragon.vm.torch.Tensor – The self.

is_floating_point

Tensor.is_floating_point()[source]

Whether the data type is floating.

Floating types contains: (float16, float32, float64)

Returns:
boolTrue if the data type is floating otherwise False.

le

Tensor.le(other)

Compute the element-wise less-equal comparison.

\[\text{out} = (\text{self} \leq \text{other}) \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.le(…) : Compute the element-wise less-equal comparison.

log

Tensor.log()

Compute the natural logarithm.

\[\text{out} = \log(\text{self}) \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

logsumexp

Tensor.logsumexp(
  dim,
  keepdim=False
)

Apply the composite of log, sum, and exp.

\[\text{LogSumExp}(x)_{i} = \log\sum_{j}\exp(x_{ij}) \]
Parameters:
  • dim (Union[int, Sequence[int]]) – The dimension(s) to reduce.
  • keepdim (bool, optional, default=False) – Whether the output tensor has dim retained or not.
Returns:

dragon.vm.torch.Tensor – The output tensor.

long

Tensor.long()

Return an int64 tensor with the same data.

Returns:
dragon.vm.torch.Tensor – The output tensor.

long_

Tensor.long_()

Cast to an int64 tensor.

Returns:
dragon.vm.torch.Tensor – The self.

lt

Tensor.lt(other)

Compute the element-wise less comparison.

\[\text{out} = (\text{self} < \text{other}) \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.lt(…) : Compute the element-wise less comparison.

masked_fill_

Tensor.masked_fill_(
  mask,
  value
)

Fill self with the given value where mask is 1.

\[\text{Ref}[i] = \begin{cases} \text{Value}[i], & \text{ if } \text{Mask}[i] = 1 \\ \text{Ref}[i], & \text{ otherwise } \end{cases} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The self.

max

Tensor.max(
  dim=None,
  keepdim=False
)

Compute the max value of elements along the given axis.

Parameters:
  • dim (Union[int, Sequence[int]], optional) – The dimension(s) to reduce.
  • keepdim (bool, optional, default=False) – Keep the reduced dimensions or not.
Returns:

dragon.vm.torch.Tensor – The output tensor.

masked_select

Tensor.masked_select(mask)

Select the elements where mask is 1.

Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

mean

Tensor.mean(
  dim=None,
  keepdim=False
)

Compute the mean value of elements along the given axis.

Parameters:
  • dim (Union[int, Sequence[int]], optional) – The dimension(s) to reduce.
  • keepdim (bool, optional, default=False) – Keep the reduced dimensions or not.
Returns:

dragon.vm.torch.Tensor – The output tensor.

min

Tensor.min(
  dim=None,
  keepdim=False
)

Compute the min value of elements along the given axis.

Parameters:
  • dim (Union[int, Sequence[int]], optional) – The dimension(s) to reduce.
  • keepdim (bool, optional, default=False) – Keep the reduced dimensions or not.
Returns:

dragon.vm.torch.Tensor – The output tensor.

mul

Tensor.mul(value)

Compute the element-wise multiplication.

\[\text{out} = \text{self} \times \text{value} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.mul(…) : Compute the element-wise multiplication.

mul_

Tensor.mul_(value)

Compute the element-wise multiplication.

\[\text{self} \mathrel{\times}= \text{value} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The self.

See also

torch.mul(…) : Compute the element-wise multiplication.

multinomial

Tensor.multinomial(
  num_samples,
  eps=0.0
)

Return a tensor where each row contains num_samples, sampled from the multinomial distribution.

Parameters:
  • num_samples (int) – The number of samples.
  • eps (float, optional, default=0.) – The prob to a uniform sampling.
Returns:

dragon.vm.torch.Tensor – The output tensor.

narrow

Tensor.narrow(
  dimension,
  start,
  length
)

Return a new tensor that is a narrowed version of input tensor.

Parameters:
  • dimension (int) – The dimension to narrow.
  • start (int) – The starting position.
  • length (int) – The distance to the ending position.
Returns:

dragon.vm.torch.Tensor – The output tensor.

ndimension

Tensor.ndimension()[source]

Alias for Tensor.dim().

Returns:
int – The number of dimensions.

ne

Tensor.ne(other)

Compute the element-wise not-equal comparison.

\[\text{out} = (\text{self} \neq \text{other}) \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.ne(…) : Compute the element-wise not-equal comparison.

nonzero

Tensor.nonzero()

Return the indices of non-zero elements.

Returns:
dragon.vm.torch.Tensor – The output tensor.

normal_

Tensor.normal_(
  mean=0,
  std=1
)

Fill self with a normal distribution.

\[\text{self} \leftarrow N(\mu, \sigma) \]
Parameters:
  • mean (number, optional, default=0) – The value of \(\mu\).
  • std (number, optional, default=1) – The value of \(\sigma\).
Returns:

dragon.vm.torch.Tensor – The self.

numel

Tensor.numel()[source]

Return the total number of elements.

Returns:
int – The total count.

numpy

Tensor.numpy(readonly=True)[source]

Create a numpy array sharing the data.

Parameters:
  • readonly (bool, optional, default=True) – False to sync the content with device.
Returns:

numpy.ndarray – The numpy array.

one_

Tensor.one_()[source]

Fill with constant 1.

\[\text{self} \leftarrow 1 \]
Returns:
dragon.vm.torch.Tensor – The self.

permute

Tensor.permute(*dims)

Return a new tensor with the specific order of dimensions.

Parameters:
  • dims (int...) – The new order of dimensions.
Returns:

dragon.vm.torch.Tensor – The output tensor.

pow

Tensor.pow(exponent)

Compute the power.

Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.pow(…) : Compute the power of input.

reciprocal

Tensor.reciprocal()

Compute the reciprocal.

\[\text{out} = \frac{1}{\text{self}} \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.reciprocal(…) : Compute the reciprocal of input.

reciprocal_

Tensor.reciprocal_()

Compute the reciprocal.

\[\text{self} = \frac{1}{\text{self}} \]
Returns:
dragon.vm.torch.Tensor – The self.

See also

torch.reciprocal(…) : Compute the reciprocal of input.

repeat

Tensor.repeat(*sizes)

Repeat elements along the specified dimensions.

Parameters:
  • sizes (int...) – The number of times to repeat.
Returns:

dragon.vm.torch.Tensor – The output tensor.

reshape

Tensor.reshape(shape)

Return a tensor with the same data but a different shape.

Parameters:
  • shape (Sequence[int]) – The new shape.
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.reshape(…) : Change the shape of input.

reshape_

Tensor.reshape_(shape)

Change into a new shape with the same data.

Parameters:
  • shape (Sequence[int]) – The new shape.
Returns:

dragon.vm.torch.Tensor – The self.

See also

torch.reshape(…) : Change the shape of input.

round

Tensor.round()

Return a tensor taken the round of elements.

\[\text{out} = \lfloor \text{self} \rceil \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.round(…) : Compute the nearest integer of input.

round_

Tensor.round_()

Set to the round of elements.

\[\text{self} = \lfloor \text{self} \rceil \]
Returns:
dragon.vm.torch.Tensor – The self.

See also

torch.round(…) : Compute the nearest integer of input.

rsqrt

Tensor.rsqrt()

Compute the reciprocal square root.

\[\text{out} = \frac{1}{\sqrt{\text{self}}} \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.rsqrt(…) : Compute the square root of input.

rsqrt_

Tensor.rsqrt_()

Compute the reciprocal square root.

\[\text{self} = \frac{1}{\sqrt{\text{self}}} \]
Returns:
dragon.vm.torch.Tensor – The self.

See also

torch.rsqrt(…) : Compute the square root of input.

sign

Tensor.sign()

Return a tensor taken the sign indication of elements.

\[\text{out}_{i} = \begin{cases} -1, & \text{ if } \text{self}_{i} < 0 \\ 0, & \text{ if } \text{self}_{i} = 0 \\ 1, & \text{ if } \text{self}_{i} > 0 \end{cases} \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.sign(…) : Compute the sign indication of input.

sign_

Tensor.sign_()

Set to the sign indication of elements.

\[\text{self}_{i} = \begin{cases} -1, & \text{ if } \text{self}_{i} < 0 \\ 0, & \text{ if } \text{self}_{i} = 0 \\ 1, & \text{ if } \text{self}_{i} > 0 \end{cases} \]
Returns:
dragon.vm.torch.Tensor – The self.

See also

torch.sign(…) : Compute the sign indication of input.

sin

Tensor.sin()

Compute the sin.

\[\text{out} = \sin(\text{self}) \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.sin(…) : Compute the sin of input.

size

Tensor.size(axis=None)[source]

Return the size of this tensor.

Parameters:
  • axis (int, optional) – The optional axis.
Returns:

dragon.vm.torch.Size – The size.

sqrt

Tensor.sqrt()

Compute the square root.

\[\text{out} = \sqrt{\text{self}} \]
Returns:
dragon.vm.torch.Tensor – The output tensor.

See also

torch.sqrt(…) : Compute the square root of input.

sqrt_

Tensor.sqrt_()

Compute the square root.

\[\text{self} = \sqrt{\text{self}} \]
Returns:
dragon.vm.torch.Tensor – The self.

See also

torch.sqrt(…) : Compute the square root of input.

squeeze

Tensor.squeeze(dim=None)

Return a tensor with dimensions of size 1 removed.

Parameters:
  • dim (Union[int, Sequence[int]], optional) – The dimension(s) to remove.
Returns:

dragon.vm.torch.Tensor – The output tensor.

squeeze_

Tensor.squeeze_(dim=None)

Inplace version of Tensor.squeeze().

Parameters:
  • dim (Union[int, Sequence[int]], optional) – The dimension(s) to remove.
Returns:

dragon.vm.torch.Tensor – The self.

sum

Tensor.sum(
  dim=None,
  keepdim=False
)

Compute the sum value of elements along the given axis.

Parameters:
  • dim (Union[int, Sequence[int]], optional) – The dimension(s) to reduce.
  • keepdim (bool, optional, default=False) – Keep the reduced dimensions or not.
Returns:

dragon.vm.torch.Tensor – The output tensor.

sub

Tensor.sub(value)

Compute the element-wise subtraction.

\[\text{out} = \text{self} - \text{value} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.sub(…) : Compute the element-wise subtraction.

sub_

Tensor.sub_(value)

Compute the element-wise subtraction.

\[\text{self} \mathrel{-}= \text{value} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The self.

See also

torch.sub(…) : Compute the element-wise subtraction.

type

Tensor.type(dtype=None)

Return the data type.

If dtype is not None, cast self to the new tensor.

Parameters:
  • dtype (str, optional) – The specified type.
Returns:

Union[str, dragon.vm.torch.Tensor] – The data type or new tensor.

uniform_

Tensor.uniform_(
  low=0,
  high=1
)

Fill self with a uniform distribution.

\[\text{self} \leftarrow U(\alpha, \beta) \]
Parameters:
  • low (number, optional, default=0) – The value of \(\alpha\).
  • high (number, optional, default=1) – The value of \(\beta\).
Returns:

dragon.vm.torch.Tensor – The self.

unsqueeze

Tensor.unsqueeze(dim)

Return a tensor with dimensions of size 1 inserted.

Parameters:
  • dim (Union[int, Sequence[int]]) – The dimensions(s) to insert.
Returns:

dragon.vm.torch.Tensor – The output tensor.

unsqueeze_

Tensor.unsqueeze_(dim)

In-place version of Tensor.unsqueeze().

Parameters:
  • dim (Union[int, Sequence[int]]) – The dimensions(s) to insert.
Returns:

dragon.vm.torch.Tensor – The self.

view

Tensor.view(*shape)[source]

Return a tensor with the same data but a different shape.

Parameters:
  • shape (int...) – The new shape
Returns:

dragon.vm.torch.Tensor – The output tensor.

See also

torch.reshape(…) : Change the shape of input.

view_

Tensor.view_(*shape)[source]

Change into a new shape with the same data.

Parameters:
  • shape (int...) – The new shape.
Returns:

dragon.vm.torch.Tensor – The self.

See also

torch.reshape(…) : Change the shape of input.

view_as

Tensor.view_as(other)[source]
Return a new tensor with the same data
but a different size as the given tensor.
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

where

Tensor.where(
  condition,
  y
)

Select the elements from two branches under the condition.

\[\text{out}[i] = \begin{cases} \text{self}[i] & \text{ if } cond[i] \text{ is True } \\ y[i], & \text{ otherwise } \end{cases} \]
Parameters:
Returns:

dragon.vm.torch.Tensor – The output tensor.

zero_

Tensor.zero_()[source]

Fill self with constant 0.

\[\text{self} \leftarrow 0 \]
Returns:
dragon.vm.torch.Tensor – The self.