torch.all(input) → Tensor
Tests if all elements in input evaluate to True.
This function matches the behaviour of NumPy in returning output of dtype bool for all supported dtypes except uint8. For uint8 the dtype of output is uint8 itself.
Example:
a = torch.rand(1, 2).bool()
a
torch.all(a)
a = torch.arange(0, 3)
a
torch.all(a)
torch.all(input, dim, keepdim=False, *, out=None) → Tensor
For each row of input in the given dimension dim, returns True if all elements in the row evaluate to True and False otherwise.
If keepdim is True, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze()), resulting in the output tensor having 1 fewer dimension than input.
Parameters:
input (Tensor) – the input tensor.
dim (int) – the dimension to reduce.
keepdim (bool) – whether the output tensor has dim retained or not.
Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
a = torch.rand(4, 2).bool()
a
torch.all(a, dim=1)
torch.all(a, dim=0)
torch.all函数用于测试输入Tensor中的所有元素是否都为真。它在行为上类似于NumPy,对于非uint8类型返回布尔值,对于uint8类型返回uint8。该函数可以按指定维度进行操作,若所有元素为真则返回True,否则返回False。如果keepdim为True,则保持维度不变,否则会挤压掉维度。
403

被折叠的 条评论
为什么被折叠?



