nansum(input, dim, keepdim=False, *, dtype=None) → Tensor¶
Returns the sum of each row of the
inputtensor in the given dimension
dim, treating Not a Numbers (NaNs) as zero. If
dimis a list of dimensions, reduce over all of them.
True, the output tensor is of the same size as
inputexcept in the dimension(s)
dimwhere it is of size 1. Otherwise,
dimis squeezed (see
oneflow.squeeze()), resulting in the output tensor having 1 (or
len(dim)) fewer dimension(s).
The interface is consistent with PyTorch. The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.nansum.html.
input (oneflow.Tensor) – the Input Tensor
dim (int, optional) – the dimension to reduce. Default:
keepdim (bool, optional) – whether the output tensor has
dimretained or not. Default: False
dtype (oneflow.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default:
>>> import oneflow as flow >>> x = flow.tensor([1., 2., float("nan")]) >>> flow.nansum(x) tensor(3., dtype=oneflow.float32) >>> x = flow.tensor([[1., float("nan")], [float("nan"), 2]]) >>> flow.nansum(x, dim=1) tensor([1., 2.], dtype=oneflow.float32) >>> x = flow.tensor([float("nan") for i in range(3)]) >>> flow.nansum(x) tensor(0., dtype=oneflow.float32)