element-wise multiplication

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2020/9/24 16:50
# @Author  : zhaoyLi
# @FileName: test2.py
# @Software: PyCharm
# @Blog    :https://blog.csdn.net/qq_37405118
# @Purpose :验证element-wise multiplication


import torch

x = torch.randn(1,3,2,2)
y = torch.tensor([[[[1.0]],

         [[2.0]],

         [[3.0]]]]) #1,3,1,1
print(y.shape)
z = torch.mul(x,y)
print(x,'\n',y,'\n',z)
print(z.shape)#1,3,2,2

#############################################**输出**##########################################
E:\Anconda\python.exe "C:/Users/MR-LI/Desktop/program practice/9-24-2020/test2.py"
torch.Size([1, 3, 1, 1])
tensor([[[[ 0.6868,  0.0787],
          [ 0.4054,  0.4241]],

         [[-1.4643, -1.7135],
          [ 0.2437,  0.4013]],

         [[-0.6950,  1.0245],
          [ 0.8811,  0.7769]]]]) 
 tensor([[[[1.]],

         [[2.]],

         [[3.]]]]) 
 tensor([[[[ 0.6868,  0.0787],
          [ 0.4054,  0.4241]],

         [[-2.9287, -3.4269],
          [ 0.4874,  0.8026]],

         [[-2.0849,  3.0734],
          [ 2.6432,  2.3306]]]])
torch.Size([1, 3, 2, 2])

你可能感兴趣的:(element-wise multiplication)