python torch.div( ) 函数使用说明

参考链接: torch.div()

 一.函数:

torch.div(input, other, out=None)  -->Tensor

 二.解释:

        Divides each element of the input input with the scalar other and returns a new resulting tensor.
        outi = inputi / other
        if input is of type FloatTensor or DoubleTensor ,other should be a real number, otherwise it should be integer.

       将输入input的每个元素与标量other相除,并返回一个新的结果张量。

        如果输入类型为FloatTensor或DoubleTensor,则other应为实数,否则应为整数

参数:
        input(Tensor)-- the input tensor
        other(Number)–the number to be divided to each element of input
        out(Tensor, optional) – the output tensor

 三.使用案例

案例一:

>>> import torch
a = >>> a = torch.randn(5)
>>> print(a)
tensor([ 0.5585, -0.4110,  0.4115, -0.8100, -1.6765])
>>> print(torch.div(a,0.5))
tensor([ 1.1169, -0.8221,  0.8230, -1.6200, -3.3530])
# 0.5585/0.5=1.1169   -0.4110/0.5=-0.8221  以此类推 

案例二: 

>>> b = torch.randn(4,4)
>>> print(b)
tensor([[-0.4071, -0.0925, -0.3788, -0.0377],
        [-0.3488, -0.3844,  0.4662,  0.8078],
        [-0.6133,  1.1852, -0.9490,  0.1832],
        [-0.3004,  1.9121,  0.4630, -0.6038]])
>>> c = torch.randn(4)
>>> print(c)
tensor([-0.7244,  0.4043,  0.0782, -0.9177])
>>> print(torch.div(b,c))
tensor([[  0.5620,  -0.2288,  -4.8435,   0.0411],
        [  0.4815,  -0.9507,   5.9605,  -0.8802],
        [  0.8466,   2.9316, -12.1326,  -0.1997],
        [  0.4146,   4.7295,   5.9190,   0.6579]])
# -0.4071/-0.7244=0.5620. 竖着除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值