当前位置:网站首页>torch. logical_ And() method
torch. logical_ And() method
2022-06-12 08:51:00 【Hey, it's me】
torch.logical_and() Element logic for computing a given input tensor AND. Zero is treated as False, Nonzero is considered True
Official documentation : https://pytorch.org/docs/stable/generated/torch.logical_and.html#torch.logical_and
torch.logical_and(input, other, *, out=None) → Return tensor
- input( tensor ) – Input tensor
- other( tensor ) – Used to calculate AND Tensor
- out ( tensor , Optional )– Output tensor
Specific examples : Enter two tensor Variable of type input and other Sum the corresponding position , If it is a tensor internal number type , Not 0 Turn into True, 0 Turn into False
1. No out Parameter type
import torch
# No out Parameter type
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) # Not 0 True, 0 False
b = torch.tensor([4, 0, 1, 0], dtype=torch.int8) # Not 0 True, 0 False
print(torch.logical_and(a, b))
Output results :
2. belt out Parameter type
Output one more suffix
import torch
# belt out Parameter type
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))) # return boolean type
# tensor([False, False, True, False])
print(torch.logical_and(a, b, out=torch.empty(4, dtype=torch.int))) # return int32 type
# tensor([0, 0, 1, 0], dtype=torch.int32)
print(torch.logical_and(a, b, out=torch.empty(4, dtype=torch.double))) # return double type
# tensor([0., 0., 1., 0.], dtype=torch.float64)
Output results :
3. Two dimensional and other examples
import torch
# Other examples
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)
# Other examples
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]])
Output results :
For note taking
My level is limited If you have any mistakes, please correct them
边栏推荐
- 报错:文件夹在另一个程序中打开无法删除怎么办
- Production scheduling status of manufacturing enterprises and solutions of APS system
- In the era of intelligent manufacturing, how do enterprises carry out digital transformation
- [new planning]
- Building a cluster: and replacing with error
- Gets the number of occurrences of a character in a string
- Oracle installation details (verification)
- FDA审查人员称Moderna COVID疫苗对5岁以下儿童安全有效
- Union selector
- Inheritance of row height
猜你喜欢

Background location case II

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

Background attribute compound writing

第三章 寄存器 (内存访问)

Loading circling effect during loading

Union selector

Inheritance of row height

Background location case 1

Background position - mixed units

处理异常数据
随机推荐
[compilation principle] understand BNF
Implementing architecture caching in MySQL under redis server environment
Application method of new version UI of idea + use method of non test qualification and related introduction
Audio and video related links
Centos8 installing MySQL 8.0 (upper)
进制GB和GiB的区别
【数据存储】浮点型数据在内存中的存储
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!
Dynamically create and submit forms
Shell basic syntax -- arithmetic operation
深拷贝与浅拷贝的区别
【指针进阶三】实现C语言快排函数qsort&回调函数
What is the beauty of MES equipment management for enterprises?
Redis installation test
Record the first step pit of date type
(node:22344) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permit
torch.logical_and()方法
Gets the number of occurrences of a character in a string
【无标题】Task3 多路召回
Engineers learn music theory (II) scale and tendency