当前位置:网站首页>torch.logical_and()方法
torch.logical_and()方法
2022-06-12 08:43:00 【嘿 是我】
torch.logical_and()计算给定输入张量的元素逻辑 AND。零被视为False,非零被视为 True
官方文档说明: https://pytorch.org/docs/stable/generated/torch.logical_and.html#torch.logical_and
torch.logical_and(input, other, *, out=None) →返回张量
- input(张量) – 输入张量
- other(张量) – 用于计算 AND 的张量
- out (张量,可选)– 输出张量
具体例子: 输入两个tensor类型的变量input和other对应的位置进行求与操作,如果是张量内部数字类型,非0转化为True, 0转化为False
1.不带out参数类型
import torch
# 不带out参数类型
a = torch.tensor([True, False, True])
b = torch.tensor([True, False, False])
print(torch.logical_and(a, b))
# tensor([ True, False, False])
a = torch.tensor([0, 1, 10, 0], dtype=torch.int8) # 非0 True, 0 False
b = torch.tensor([4, 0, 1, 0], dtype=torch.int8) # 非0 True, 0 False
print(torch.logical_and(a, b))
输出结果:
2.带out参数类型
输出多一个后缀
import torch
# 带out参数类型
a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
print(torch.logical_and(a, b, out=torch.empty(4, dtype=torch.bool))) # 返回boolean类型
# tensor([False, False, True, False])
print(torch.logical_and(a, b, out=torch.empty(4, dtype=torch.int))) # 返回int32类型
# tensor([0, 0, 1, 0], dtype=torch.int32)
print(torch.logical_and(a, b, out=torch.empty(4, dtype=torch.double))) # 返回double类型
# tensor([0., 0., 1., 0.], dtype=torch.float64)
输出结果:
3.二维和其他例子
import torch
# 其他例子
a = torch.tensor([0, 1, 3, 2, 2])
b = torch.tensor([1, 1, 0, 1, 2])
print(a == b) # tensor([False, True, False, False, True])
print(b != 2) # tensor([ True, True, True, True, False])
print(torch.logical_and(a==b, b != 2))
# tensor([False, True, False, False, False])
print("=" * 100)
# 其他例子
a = torch.tensor([[0, 1, 3, 2, 2],
[0, 3, 1, 0, 2]])
b = torch.tensor([[1, 1, 0, 1, 2],
[1, 1, 2, 0, 2]])
print(torch.logical_and(a, b))
# tensor([[False, True, False, True, True],
# [False, True, True, False, True]])
输出结果:
用于笔记记录
本人水平有限 如有错误欢迎指正交流
边栏推荐
- 第八章-数据处理的两个基本问题
- [advanced pointer I] character array & array pointer & pointer array
- [advanced pointer III] implement C language quick sorting function qsort & callback function
- 动态创建表单并提交
- Engineers learn music theory (II) scale and tendency
- Audio and video engineer (Preliminary) (I) basic concepts of audio and video
- Calling stored procedures in mysql, definition of variables,
- [advanced pointer 2] array parameter transfer & pointer parameter transfer & function pointer & function pointer array & callback function
- Oracle installation details (verification)
- The residual pressure monitoring system ensures the smoothness of the fire evacuation passage in case of fire, and protects the safe operation of large high-rise buildings and the safety of people's l
猜你喜欢

报错:清除网站内搜索框中的历史记录?

Adjust SVG width and height

(p21-p24) unified data initialization method: List initialization, initializing objects of non aggregate type with initialization list, initializer_ Use of Lisy template class

调整svg宽高

(p17-p18) define the basic type and function pointer alias by using, and define the alias for the template by using and typedef

Regular expressions in JS
![[essence] explain in detail the memory management mechanism in QT](/img/7d/0d83158c6b0574dd3b3547b47af67e.jpg)
[essence] explain in detail the memory management mechanism in QT

Application method of new version UI of idea + use method of non test qualification and related introduction
![[advanced pointer I] character array & array pointer & pointer array](/img/ea/150b2162e4e1641eee7e852935d101.png)
[advanced pointer I] character array & array pointer & pointer array

了结非对称密钥
随机推荐
When converting tensor to ndarray in tensorflow, the run or Eval function is constantly called in the loop, and the code runs more and more slowly!
What scheduling rules does the APS software have? What is the exception handling scheme?
Regularization to limit the number of digits after the decimal point of an input number
(p19-p20) delegate constructor (proxy constructor) and inheritance constructor (using)
第三章 寄存器 (内存访问)
Background position position NOUN
Adjust SVG width and height
The residual pressure monitoring system ensures the smoothness of the fire evacuation passage in case of fire, and protects the safe operation of large high-rise buildings and the safety of people's l
Shell basic syntax -- array
UMI packaging and subcontracting, and compressing to gzip
判断对象是否为空
What is the beauty of MES equipment management for enterprises?
Convert spaces to < br / > newline labels
【字符集七】汉字的宽字符码和多字节码分别是多少
Production scheduling status of manufacturing enterprises and solutions of APS system
FDA审查人员称Moderna COVID疫苗对5岁以下儿童安全有效
《MATLAB 神經網絡43個案例分析》:第7章 RBF網絡的回歸--非線性函數回歸的實現
In the era of intelligent manufacturing, how do enterprises carry out digital transformation
X64dbg debugging exception_ ACCESS_ VIOLATION C0000005
[essence] explain in detail the memory management mechanism in QT