本文簡要介紹python語言中 torch.all 的用法。
用法:
torch.all(input) → Tensorout(Tensor,可選的) -輸出張量。
測試
input中的所有元素是否評估為True。注意
此函數與 NumPy 的行為相匹配,為除
uint8之外的所有受支持的數據類型返回數據類型bool的輸出。對於uint8,輸出的數據類型是uint8本身。例子:
>>> a = torch.rand(1, 2).bool() >>> a tensor([[False, True]], dtype=torch.bool) >>> torch.all(a) tensor(False, dtype=torch.bool) >>> a = torch.arange(0, 3) >>> a tensor([0, 1, 2]) >>> torch.all(a) tensor(False)torch.all(input, dim, keepdim=False, *, out=None) → Tensor
對於給定維度
dim中input的每一行,如果該行中的所有元素評估為True,則返回True,否則返回False。如果
keepdim是True,則輸出張量的大小與input相同,但在維度dim中它的大小為 1。否則,dim被擠壓(參見torch.squeeze()),結果在比input少 1 個維度的輸出張量中。例子:
>>> a = torch.rand(4, 2).bool() >>> a tensor([[True, True], [True, False], [True, True], [True, True]], dtype=torch.bool) >>> torch.all(a, dim=1) tensor([ True, False, True, True], dtype=torch.bool) >>> torch.all(a, dim=0) tensor([ True, False], dtype=torch.bool)
參數:
關鍵字參數:
相關用法
- Python PyTorch all_reduce用法及代碼示例
- Python PyTorch all_gather用法及代碼示例
- Python PyTorch allreduce_hook用法及代碼示例
- Python PyTorch all_to_all用法及代碼示例
- Python PyTorch allclose用法及代碼示例
- Python PyTorch all_gather_object用法及代碼示例
- Python PyTorch argsort用法及代碼示例
- Python PyTorch addmm用法及代碼示例
- Python PyTorch addmv用法及代碼示例
- Python PyTorch apply_effects_tensor用法及代碼示例
- Python PyTorch assert_close用法及代碼示例
- Python PyTorch angle用法及代碼示例
- Python PyTorch atanh用法及代碼示例
- Python PyTorch annotate用法及代碼示例
- Python PyTorch async_execution用法及代碼示例
- Python PyTorch argmax用法及代碼示例
- Python PyTorch atan用法及代碼示例
- Python PyTorch as_strided用法及代碼示例
- Python PyTorch acos用法及代碼示例
- Python PyTorch avg_pool1d用法及代碼示例
- Python PyTorch asin用法及代碼示例
- Python PyTorch argmin用法及代碼示例
- Python PyTorch any用法及代碼示例
- Python PyTorch asinh用法及代碼示例
- Python PyTorch add用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.all。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
