Returns the median value of each row of the x tensor in the given dimension dim. Also returns the index location of the median value as a LongTensor.

tch_median(x, dim = NULL, keepdim = FALSE)

Arguments

x

tensor object

dim

the dimension to reduce

keepdim

wether to keep or not the dim

Details

By default, dim is the last dimension of the x tensor.

Examples

x <- tensor(array(1:20, c(5,4))) tch_median(x)
#> tensor #> 10 #> [ Variable[CPUIntType]{} ]
tch_median(x, 0)
#> [[1]] #> tensor #> 3 #> 8 #> 13 #> 18 #> [ Variable[CPUIntType]{4} ] #> #> [[2]] #> tensor #> 2 #> 2 #> 2 #> 2 #> [ Variable[CPULongType]{4} ] #>
tch_median(x, 1)
#> [[1]] #> tensor #> 6 #> 7 #> 8 #> 9 #> 10 #> [ Variable[CPUIntType]{5} ] #> #> [[2]] #> tensor #> 1 #> 1 #> 1 #> 1 #> 1 #> [ Variable[CPULongType]{5} ] #>