0

0

PyTorch 中的子项目

DDD

DDD

发布时间:2025-01-02 18:32:30

|

630人浏览过

|

来源于dev.to

转载

请我喝杯咖啡☕

*备忘录:

  • 我的帖子解释了 add()。
  • 我的帖子解释了 mul()。
  • 我的帖子解释了 div()。
  • 我的帖子解释了余​​数()。
  • 我的帖子解释了 fmod()。

sub() 可以与零个或多个元素或标量的 0d 或多个 d 张量中的两个或零个或多个元素的 0d 或多个 d 张量与一个标量进行减法,得到为零的 0d 或多个 d 张量或更多元素,如下所示:

Web项目中实现 iOS 风格的通知和提示效果
Web项目中实现 iOS 风格的通知和提示效果

Web项目中实现 iOS 风格的通知和提示效果

下载

*备忘录:

  • sub() 可以与 torch 或张量一起使用。
  • 第一个参数(输入)带有 torch(类型:int、float 或complex 的张量或标量)或使用张量(类型:int、float 或complex 的张量)(必需)。
  • 带有 torch 的第二个参数或带有张量的第一个参数是其他(必需类型:张量或 int、float 或complex 标量)。
  • 带有 torch 的第三个参数或带有张量的第二个参数是 alpha(可选-默认:1-类型:张量或整数、浮点或复数标量)。 *other 乘以 alpha(输入或张量 -(otherxalpha))。
  • torch 存在 out 参数(可选-默认:无-类型:张量): *备注:
    • 必须使用 out=。
    • 我的帖子解释了论点。
  • minus() 是 sub() 的别名。
import torch

tensor1 = torch.tensor([9, 7, 6])
tensor2 = torch.tensor([[4, -4, 3], [-2, 5, -5]])

torch.sub(input=tensor1, other=tensor2)
tensor1.sub(other=tensor2)
torch.sub(input=tensor1, other=tensor2, alpha=1)
torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(1))
# tensor([[5, 11, 3], [11, 2, 11]])

torch.sub(input=tensor1, other=tensor2, alpha=0)
torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(0))
# tensor([[9, 7, 6], [9, 7, 6]])

torch.sub(input=tensor1, other=tensor2, alpha=2)
torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(2))
# tensor([[1, 15, 0], [13, -3, 16]])

torch.sub(input=tensor1, other=tensor2, alpha=-1)
torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(-1))
# tensor([[13, 3, 9], [7, 12, 1]])

torch.sub(input=tensor1, other=tensor2, alpha=-2)
torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(-2))
# tensor([[17, -1, 12], [5, 17, -4]])

torch.sub(input=9, other=tensor2)
torch.sub(input=9, other=tensor2, alpha=1)
torch.sub(input=9, other=tensor2, alpha=torch.tensor(1))
# tensor([[5, 13, 6], [11, 4, 14]])

torch.sub(input=tensor1, other=4)
torch.sub(input=tensor1, other=4, alpha=1)
torch.sub(input=tensor1, other=4, alpha=torch.tensor(1))
# tensor([5, 3, 2])

torch.sub(input=9, other=4)
torch.sub(input=9, other=4, alpha=1)
torch.sub(input=9, other=4, alpha=torch.tensor(1))
# tensor(5)

tensor1 = torch.tensor([9., 7., 6.])
tensor2 = torch.tensor([[4., -4., 3.], [-2., 5., -5.]])

torch.sub(input=tensor1, other=tensor2)
torch.sub(input=tensor1, other=tensor2, alpha=1.)
torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(1.))
# tensor([[5., 11., 3.], [11., 2., 11.]])

torch.sub(input=9., other=tensor2)
torch.sub(input=9., other=tensor2, alpha=1.)
torch.sub(input=9., other=tensor2, alpha=torch.tensor(1.))
# tensor([[5., 13., 6.], [11., 4., 14.]])

torch.sub(input=tensor1, other=4)
torch.sub(input=tensor1, other=4, alpha=1.)
torch.sub(input=tensor1, other=4, alpha=torch.tensor(1.))
# tensor([5., 3., 2.])

torch.sub(input=9., other=4)
torch.sub(input=9., other=4, alpha=1.)
torch.sub(input=9., other=4, alpha=torch.tensor(1.))
# tensor(5.)

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.sub(input=tensor1, other=tensor2)
torch.sub(input=tensor1, other=tensor2, alpha=1.+0.j)
torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(1.+0.j))
# tensor([[5.+0.j, 11.+0.j, 3.+0.j],
#         [11.+0.j, 2.+0.j, 11.+0.j]])

torch.sub(input=9.+0.j, other=tensor2)
torch.sub(input=9.+0.j, other=tensor2, alpha=1.+0.j)
torch.sub(input=9.+0.j, other=tensor2, alpha=torch.tensor(1.+0.j))
# tensor([[5.+0.j, 13.+0.j, 6.+0.j],
#         [11.+0.j, 4.+0.j, 14.+0.j]])

torch.sub(input=tensor1, other=4.+0.j)
torch.sub(input=tensor1, other=4.+0.j, alpha=1.+0.j)
torch.sub(input=tensor1, other=4.+0.j, alpha=torch.tensor(1.+0.j))
# tensor([5.+0.j, 3.+0.j, 2.+0.j])

torch.sub(input=9.+0.j, other=4.+0.j)
torch.sub(input=9.+0.j, other=4.+0.j, alpha=1.+0.j)
torch.sub(input=9.+0.j, other=4.+0.j, alpha=torch.tensor(1.+0.j))
# tensor(5.+0.j)

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
css中float用法
css中float用法

css中float属性允许元素脱离文档流并沿其父元素边缘排列,用于创建并排列、对齐文本图像、浮动菜单边栏和重叠元素。想了解更多float的相关内容,可以阅读本专题下面的文章。

553

2024.04.28

C++中int、float和double的区别
C++中int、float和double的区别

本专题整合了c++中int和double的区别,阅读专题下面的文章了解更多详细内容。

95

2025.10.23

string转int
string转int

在编程中,我们经常会遇到需要将字符串(str)转换为整数(int)的情况。这可能是因为我们需要对字符串进行数值计算,或者需要将用户输入的字符串转换为整数进行处理。php中文网给大家带来了相关的教程以及文章,欢迎大家前来学习阅读。

312

2023.08.02

int占多少字节
int占多少字节

int占4个字节,意味着一个int变量可以存储范围在-2,147,483,648到2,147,483,647之间的整数值,在某些情况下也可能是2个字节或8个字节,int是一种常用的数据类型,用于表示整数,需要根据具体情况选择合适的数据类型,以确保程序的正确性和性能。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

522

2024.08.29

c++怎么把double转成int
c++怎么把double转成int

本专题整合了 c++ double相关教程,阅读专题下面的文章了解更多详细内容。

48

2025.08.29

C++中int的含义
C++中int的含义

本专题整合了C++中int相关内容,阅读专题下面的文章了解更多详细内容。

190

2025.08.29

pytorch是干嘛的
pytorch是干嘛的

pytorch是一个基于python的深度学习框架,提供以下主要功能:动态图计算,提供灵活性。强大的张量操作,实现高效处理。自动微分,简化梯度计算。预构建的神经网络模块,简化模型构建。各种优化器,用于性能优化。想了解更多pytorch的相关内容,可以阅读本专题下面的文章。

428

2024.05.29

Python AI机器学习PyTorch教程_Python怎么用PyTorch和TensorFlow做机器学习
Python AI机器学习PyTorch教程_Python怎么用PyTorch和TensorFlow做机器学习

PyTorch 是一种用于构建深度学习模型的功能完备框架,是一种通常用于图像识别和语言处理等应用程序的机器学习。 使用Python 编写,因此对于大多数机器学习开发者而言,学习和使用起来相对简单。 PyTorch 的独特之处在于,它完全支持GPU,并且使用反向模式自动微分技术,因此可以动态修改计算图形。

7

2025.12.22

php源码安装教程大全
php源码安装教程大全

本专题整合了php源码安装教程,阅读专题下面的文章了解更多详细内容。

7

2025.12.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号