dev-resources.site
for different kinds of informations.
mul in PyTorch
Published at
12/30/2024
Categories
python
pytorch
mul
function
Author
hyperkai
Main Article
Author
8 person written this
hyperkai
open
*Memos:
- My post explains add().
- My post explains sub().
- My post explains div().
- My post explains remainder().
- My post explains fmod().
mul() can do multiplication with two of the 0D or more D tensors of zero or more elements or scalars or the 0D or more D tensor of zero or more elements and a scalar. getting the 0D or more D tensor of zero or more elements as shown below:
*Memos:
-
mul()
can be used with torch or a tensor. - The 1st argument(
input
) withtorch
(Type:tensor
orscalar
ofint
,float
,complex
orbool
) or using a tensor(Type:tensor
ofint
,float
,complex
orbool
)(Required). - The 2nd argument with
torch
or the 1st argument with a tensor isother
(Required-Type:tensor
orscalar
ofint
,float
,complex
orbool
). - There is
out
argument withtorch
(Optional-Default:None
-Type:tensor
): *Memos:-
out=
must be used. -
My post explains
out
argument.
-
-
multiply() is the alias of
mul()
.
import torch
tensor1 = torch.tensor([9, 7, 6])
tensor2 = torch.tensor([[4, -4, 3], [-2, 5, -5]])
torch.mul(input=tensor1, other=tensor2)
tensor1.mul(other=tensor2)
# tensor([[36, -28, 18], [-18, 35, -30]])
torch.mul(input=9, other=tensor2)
# tensor([[36, -36, 27], [-18, 45, -45]])
torch.mul(input=tensor1, other=4)
# tensor([36, 28, 24])
torch.mul(input=9, other=4)
# tensor(36)
tensor1 = torch.tensor([9., 7., 6.])
tensor2 = torch.tensor([[4., -4., 3.], [-2., 5., -5.]])
torch.mul(input=tensor1, other=tensor2)
# tensor([[36., -28., 18.], [-18., 35., -30.]])
torch.mul(input=9., other=tensor2)
# tensor([[36., -36., 27.], [-18., 45., -45.]])
torch.mul(input=tensor1, other=4.)
# tensor([36., 28., 24.])
torch.mul(input=9., other=4.)
# tensor(36.)
tensor1 = torch.tensor([9.+0.j, 7.+0.j, 6.+0.j])
tensor2 = torch.tensor([[4.+0.j, -4.+0.j, 3.+0.j],
[-2.+0.j, 5.+0.j, -5.+0.j]])
torch.mul(input=tensor1, other=tensor2)
# tensor([[36.+0.j, -28.+0.j, 18.+0.j],
# [-18.+0.j, 35.+0.j, -30.+0.j]])
torch.mul(input=9.+0.j, other=tensor2)
# tensor([[36.+0.j, -36.+0.j, 27.+0.j],
# [-18.+0.j, 45.+0.j, -45.+0.j]])
torch.mul(input=tensor1, other=4.+0.j)
# tensor([36.+0.j, 28.+0.j, 24.+0.j])
torch.mul(input=9.+0.j, other=4.+0.j)
# tensor(36.+0.j)
tensor1 = torch.tensor([True, False, True])
tensor2 = torch.tensor([[False, True, False], [True, False, True]])
torch.mul(input=tensor1, other=tensor2)
# tensor([[False, False, False],
# [True, False, True]])
torch.mul(input=True, other=tensor2)
# tensor([[False, True, False], [True, False, True]])
torch.mul(input=tensor1, other=False)
# tensor([False, False, False])
torch.mul(input=True, other=False)
# tensor(False)
pytorch Article's
30 articles in total
Face Recognition with Python and FaceNet
read article
RandomAffine in PyTorch
read article
CocoCaptions in PyTorch (2)
read article
CocoDetection in PyTorch (3)
read article
CocoDetection in PyTorch (2)
read article
square in PyTorch
read article
any in PyTorch
read article
atleast_2d in PyTorch
read article
atleast_1d in PyTorch
read article
atleast_3d in PyTorch
read article
fmod in PyTorch
read article
remainder in PyTorch
read article
sub in PyTorch
read article
mul in PyTorch
currently reading
linspace in PyTorch
read article
arange in PyTorch
read article
unsqueeze in PyTorch
read article
squeeze in PyTorch
read article
all in PyTorch
read article
ColorJitter in PyTorch
read article
ImageNet in PyTorch
read article
Asynchronous Python: What You Need to Know ๐๐๐
read article
Install PyTorch and JupyterLab on Ubuntu
read article
Datasets for Computer Vision (5)
read article
AI Pronunciation Trainer
read article
CocoCaptions in PyTorch (1)
read article
CocoCaptions in PyTorch (3)
read article
CocoDetection in PyTorch (1)
read article
pow in PyTorch
read article
Why PyTorch Stole the Spotlight from TensorFlow?
read article
Featured ones: