Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.nanquantile function

PyTorch torch.nanquantile function


PyTorch torch reference manual PyTorch torch reference manual

torch.nanquantile is a function in PyTorch used to return the quantiles of the non-NaN values of a tensor. Unlike quantile, it ignores all NaN values.

Function definition

torch.nanquantile(input, q, dim, keepdim=False)


Usage examples

Example

import

torch

x

=

torch.

tensor

(

[

1.0

,

float

(

'nan'

)

,

3.0

,

4.0

,

5.0

,

6.0

,

7.0

,

8.0

,

9.0

,

10.0

]

)

Return the 0.5 quantile of non-NaN values

print

(

"Non-NaN 0.5 quantile:"

,

torch.

nanquantile

(

x

,

0.5

)

)

Return multiple non-NaN quantiles

print

(

"Non-NaN 0.25, 0.75 quantiles:"

,

torch.

nanquantile

(

x

,

torch.

tensor

(

[

0.25

,

0.75

]

)

)

)

Non-NaN quantiles along dim=0

y

=

torch.

tensor

(

[

[

1.0

,

float

(

'nan'

)

,

3.0

]

,

[

4.0

,

5.0

,

6.0

]

]

)

print

(

"dim=0 non-NaN 0.5 quantile:"

,

torch.

nanquantile

(

y

,

0.5

,

dim

=

0

)

)

The output is:

非NaN 0.5 分位数: tensor(5.5000)

非NaN 0.25, 0.75 分位数: tensor([2.7500, 7.7500])

dim=0 非NaN 0.5 分位数: tensor([2.5000, 5.0000, 4.5000])


PyTorch torch reference manual PyTorch torch reference manual