pytorch tensor.all() tensor.any()

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)
发布了489 篇原创文章 · 获赞 101 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/littlehaes/article/details/103945686