总结
豆包 AI 助手文章总结

PyTorch 中的 eq 和 ne

霞舞
发布: 2024-11-05 09:09:34
转载
360人浏览过

pytorch 中的 eq 和 ne

请我喝杯咖啡☕

*备忘录:

  • 我的帖子解释了 gt() 和 lt()。
  • 我的帖子解释了 ge() 和 le()。
  • 我的帖子解释了 isclose() 和 equal()。

eq() 可以检查第一个 0d 或更多 d 张量的零个或多个元素是否等于第二个 0d 或更多 d 张量的零个或多个元素,得到 0d 或更多 d 张量零个或多个元素,如下所示:

*备忘录:

  • eq() 可以与 torch 或张量一起使用。
  • 第一个参数(输入)使用 torch 或使用张量(必需类型:int、float、complex 或 bool 的张量)。
  • 带有 torch 的第二个参数或带有张量的第一个参数是其他(必需类型:张量或 int、float、complex 或 bool 标量)。
  • torch 存在 out 参数(可选-默认:无-类型:张量): *备注:
    • 必须使用 out=。
    • 我的帖子解释了论点。
  • 结果是具有更多元素的更高 d 张量。
import torch

tensor1 = torch.tensor([5, 0, 3])
tensor2 = torch.tensor([7, 0, 3])

torch.eq(input=tensor1, other=tensor2)
tensor1.eq(other=tensor2)
torch.eq(input=tensor2, other=tensor1)
# tensor([false, true, true])

tensor1 = torch.tensor(5)
tensor2 = torch.tensor([[3, 5, 4],
                        [6, 3, 5]])
torch.eq(input=tensor1, other=tensor2)
torch.eq(input=tensor2, other=tensor1)
# tensor([[false, true, false],
#         [false, false, true]])

torch.eq(input=tensor1, other=3)
# tensor(false)

torch.eq(input=tensor2, other=3)
# tensor([[true, false, false],
#         [false, true, false]])

tensor1 = torch.tensor([5, 0, 3])
tensor2 = torch.tensor([[5, 5, 5],
                        [0, 0, 0],
                        [3, 3, 3]])
torch.eq(input=tensor1, other=tensor2)
torch.eq(input=tensor2, other=tensor1)
# tensor([[true, false, false],
#         [false, true, false], 
#         [false, false, true]])

torch.eq(input=tensor1, other=3)
# tensor([false, false, true])

torch.eq(input=tensor2, other=3)
# tensor([[false, false, false],
#         [false, false, false],
#         [true, true, true]])

tensor1 = torch.tensor([5., 0., 3.])
tensor2 = torch.tensor([[5., 5., 5.],
                        [0., 0., 0.],
                        [3., 3., 3.]])
torch.eq(input=tensor1, other=tensor2)
# tensor([[true, false, false],
#         [false, true, false], 
#         [false, false, true]])

torch.eq(input=tensor1, other=3.)
# tensor([false, false, true])

tensor1 = torch.tensor([5.+0.j, 0.+0.j, 3.+0.j])
tensor2 = torch.tensor([[5.+0.j, 5.+0.j, 5.+0.j],
                        [0.+0.j, 0.+0.j, 0.+0.j],
                        [3.+0.j, 3.+0.j, 3.+.0j]])
torch.eq(input=tensor1, other=tensor2)
# tensor([[true, false, false],
#         [false, true, false],
#         [false, false, true]])

torch.eq(input=tensor1, other=3.+0.j)
# tensor([false, false, true])

tensor1 = torch.tensor([true, false, true])
tensor2 = torch.tensor([[true, false, true],
                        [false, true, false],
                        [true, false, true]])
torch.eq(input=tensor1, other=tensor2)
# tensor([[true, true, true],
#         [false, false, false],
#         [true, true, true]])

torch.eq(input=tensor1, other=true)
# tensor([true, false, true])
登录后复制

ne() 可以按元素检查第一个 0d 或更多 d 张量的零个或多个元素是否不等于第二个 0d 或更多 d 张量的零个或多个元素,得到 0d 或更多 d 张量零个或多个元素,如下所示:

*备忘录:

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

tensor1 = torch.tensor([5, 0, 3])
tensor2 = torch.tensor([7, 0, 3])

torch.ne(input=tensor1, other=tensor2)
tensor1.ne(other=tensor2)
torch.ne(input=tensor2, other=tensor1)
# tensor([True, False, False])

tensor1 = torch.tensor(5)
tensor2 = torch.tensor([[3, 5, 4],
                        [6, 3, 5]])
torch.ne(input=tensor1, other=tensor2)
torch.ne(input=tensor2, other=tensor1)
# tensor([[True, False, True],
#         [True, True, False]])

torch.ne(input=tensor1, other=3)
# tensor(True)

torch.ne(input=tensor2, other=3)
# tensor([[False, True, True],
#         [True, False, True]])

tensor1 = torch.tensor([5, 0, 3])
tensor2 = torch.tensor([[5, 5, 5],
                        [0, 0, 0],
                        [3, 3, 3]])
torch.ne(input=tensor1, other=tensor2)
torch.ne(input=tensor2, other=tensor1)
# tensor([[False, True, True],
#         [True, False, True],
#         [True, True, False]])

torch.ne(input=tensor1, other=3)
# tensor([True, True, False])

torch.ne(input=tensor2, other=3)
# tensor([[True, True, True],
#         [True, True, True],
#         [False, False, False]])

tensor1 = torch.tensor([5., 0., 3.])
tensor2 = torch.tensor([[5., 5., 5.],
                        [0., 0., 0.],
                        [3., 3., 3.]])
torch.ne(input=tensor1, other=tensor2)
# tensor([[False, True, True],
#         [True, False, True],
#         [True, True, False]])

torch.ne(input=tensor1, other=3.)
# tensor([True, True, False])

tensor1 = torch.tensor([5.+0.j, 0.+0.j, 3.+0.j])
tensor2 = torch.tensor([[5.+0.j, 5.+0.j, 5.+0.j],
                        [0.+0.j, 0.+0.j, 0.+0.j],
                        [3.+0.j, 3.+0.j, 3.+.0j]])
torch.ne(input=tensor1, other=tensor2)
# tensor([[False, True, True],
#         [True, False, True],
#         [True, True, False]])

torch.ne(input=tensor1, other=3.+0.j)
# tensor([True, True, False])

tensor1 = torch.tensor([True, False, True])
tensor2 = torch.tensor([[True, False, True],
                        [False, True, False],
                        [True, False, True]])
torch.ne(input=tensor1, other=tensor2)
# tensor([[False, False, False],
#         [True, True, True],
#         [False, False, False]])

torch.ne(input=tensor1, other=True)
# tensor([False, True, False])
登录后复制

以上就是PyTorch 中的 eq 和 ne的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
相关标签:
来源:dev.to网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
豆包 AI 助手文章总结
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

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