oneflow.any

oneflow.any(input, dim=None, keepdim=False)Tensor

For each row of input in the given dimension dim, returns True if any element in the row evaluate to True and False otherwise. If the dimension is None, compute if any elements in the input tensor to true.

If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed oneflow.squeeze(), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s).

Parameters
  • input (oneflow.Tensor) – the Input Tensor

  • dim (int, optional) – the dimension to reduce. Default: None

  • keepdim (bool, optional) – whether the output tensor has dim retained or not. Default: False

For example:

>>> import oneflow as flow

>>> input = flow.Tensor([[1, 2, 3], [4, 5, 6]]) < 4
>>> input
tensor([[ True,  True,  True],
        [False, False, False]], dtype=oneflow.bool)
>>> flow.any(input)
tensor(True, dtype=oneflow.bool)
>>> flow.any(input, 0)
tensor([True, True, True], dtype=oneflow.bool)
>>> flow.any(input, 0, True)
tensor([[True, True, True]], dtype=oneflow.bool)