oneflow.nansum¶
-
oneflow.nansum(input, dim, keepdim=False, *, dtype=None) → Tensor¶ Returns the sum of each row of the
inputtensor in the given dimensiondim, treating Not a Numbers (NaNs) as zero. Ifdimis a list of dimensions, reduce over all of them.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seeoneflow.squeeze()), resulting in the output tensor having 1 (orlen(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.
- Parameters
input (oneflow.Tensor) – the Input Tensor
dim (int, optional) – the dimension to reduce. Default:
Nonekeepdim (bool, optional) – whether the output tensor has
dimretained or not. Default: Falsedtype (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:
None.
Example:
>>> 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)