pytorch tensor.all() tensor.any()

丁鸿云
2023-12-01

welcome to my blog

tensor.any()功能: 如果张量tensor中存在一个元素为True, 那么返回True; 只有所有元素都是False时才返回False

import torch
a = torch.tensor([True,True,False])
print(a.any())
# 打印结果 tensor(True)

b = torch.tensor([False, False, False])
print(b.any())
# 打印结果 tensor(False)

tensor.all()功能: 如果张量tensor中所有元素都是True, 才返回True; 否则返回False

import torch
a = torch.tensor([True,True,False])
print(a.all())
# 打印结果 tensor(False)

b = torch.tensor([True,True,True])
print(b.all())
# 打印结果 tensor(True)
 类似资料:

相关阅读

相关文章

相关问答