栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python torch div()函数

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python torch div()函数

python torch div()函数 一、描述

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(Tensor)-- the input tensor
  • other(Number)–the number to be divided to each element of input
  • out(Tensor, optional) – the output tensor
四、实例 实例1
>>> 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  以此类推 
实例2
>>> 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. 竖着除
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/339433.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号