Shortcuts

torch.mul

torch.mul(input, other, out=None)

Multiplies each element of the input input with the scalar other and returns a new resulting tensor.

outi=other×inputi\text{out}_i = \text{other} \times \text{input}_i

If input is of type FloatTensor or DoubleTensor, other should be a real number, otherwise it should be an integer

Parameters
  • {input}

  • value (Number) – the number to be multiplied to each element of input

  • {out}

Example:

>>> a = torch.randn(3)
>>> a
tensor([ 0.2015, -0.4255,  2.6087])
>>> torch.mul(a, 100)
tensor([  20.1494,  -42.5491,  260.8663])
torch.mul(input, other, out=None)

Each element of the tensor input is multiplied by the corresponding element of the Tensor other. The resulting tensor is returned.

The shapes of input and other must be broadcastable.

outi=inputi×otheri\text{out}_i = \text{input}_i \times \text{other}_i
Parameters
  • input (Tensor) – the first multiplicand tensor

  • other (Tensor) – the second multiplicand tensor

  • out (Tensor, optional) – the output tensor.

Example:

>>> a = torch.randn(4, 1)
>>> a
tensor([[ 1.1207],
        [-0.3137],
        [ 0.0700],
        [ 0.8378]])
>>> b = torch.randn(1, 4)
>>> b
tensor([[ 0.5146,  0.1216, -0.5244,  2.2382]])
>>> torch.mul(a, b)
tensor([[ 0.5767,  0.1363, -0.5877,  2.5083],
        [-0.1614, -0.0382,  0.1645, -0.7021],
        [ 0.0360,  0.0085, -0.0367,  0.1567],
        [ 0.4312,  0.1019, -0.4394,  1.8753]])

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources