torch.any#
- torch.any(input: Tensor, *, out: Optional[Tensor]) Tensor#
測試
input中的任何元素是否評估為 True。注意
此函式與 NumPy 的行為相匹配,即對於所有支援的 dtype(uint8 除外),返回 bool 型別的輸出。對於 uint8,輸出的 dtype 是 uint8 本身。
示例
>>> a = torch.rand(1, 2).bool() >>> a tensor([[False, True]], dtype=torch.bool) >>> torch.any(a) tensor(True, dtype=torch.bool) >>> a = torch.arange(0, 3) >>> a tensor([0, 1, 2]) >>> torch.any(a) tensor(True)
- torch.any(input, dim, keepdim=False, *, out=None) Tensor
對於給定維度
dim中的input的每一行,如果該行中的任何元素評估為 True,則返回 True,否則返回 False。如果
keepdim為True,則輸出張量的大小與input相同,只有在dim維度上大小為 1。否則,dim將被擠壓(參見torch.squeeze()),導致輸出張量維度減少 1(或len(dim))個。- 引數
- 關鍵字引數
out (Tensor, optional) – 輸出張量。
示例
>>> a = torch.randn(4, 2) < 0 >>> a tensor([[ True, True], [False, True], [ True, True], [False, False]]) >>> torch.any(a, 1) tensor([ True, True, True, False]) >>> torch.any(a, 0) tensor([True, True])