torch.nansum#
- torch.nansum(input,*,dtype=None)→Tensor#
Returns the sum of all elements, treating Not a Numbers (NaNs) as zero.
- Parameters
input (Tensor) – the input tensor.
- Keyword Arguments
dtype (
torch.dtype, optional) – the desired data type of returned tensor.If specified, the input tensor is casted todtypebefore the operationis performed. This is useful for preventing data type overflows. Default: None.
Example:
>>>a=torch.tensor([1.,2.,float('nan'),4.])>>>torch.nansum(a)tensor(7.)
- torch.nansum(input,dim,keepdim=False,*,dtype=None)→Tensor
Returns the sum of each row of the
inputtensor in the givendimensiondim, 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 sizeasinputexcept in the dimension(s)dimwhere it is of size 1.Otherwise,dimis squeezed (seetorch.squeeze()), resulting in theoutput tensor having 1 (orlen(dim)) fewer dimension(s).- Parameters
- Keyword Arguments
dtype (
torch.dtype, optional) – the desired data type of returned tensor.If specified, the input tensor is casted todtypebefore the operationis performed. This is useful for preventing data type overflows. Default: None.
Example:
>>>torch.nansum(torch.tensor([1.,float("nan")]))tensor(1.)>>>a=torch.tensor([[1,2],[3.,float("nan")]])>>>torch.nansum(a)tensor(6.)>>>torch.nansum(a,dim=0)tensor([4., 2.])>>>torch.nansum(a,dim=1)tensor([3., 3.])