Returns the mode value of each row of the x tensor in the given dimension dim. Also returns the index location of the mode value as a LongTensor. By default, dim is the last dimension of the x tensor.

tch_mode(x, dim = -1, keepdim = FALSE)

Arguments

x

tensor object

dim

the dimension to reduce

keepdim

wether to keep or not the dim

Examples

x <- tensor(array(1:20, c(5,4))) tch_mode(x)
#> [[1]] #> tensor #> 1 #> 2 #> 3 #> 4 #> 5 #> [ Variable[CPUIntType]{5} ] #> #> [[2]] #> tensor #> 0 #> 0 #> 0 #> 0 #> 0 #> [ Variable[CPULongType]{5} ] #>
tch_mode(x, 0)
#> [[1]] #> tensor #> 1 #> 6 #> 11 #> 16 #> [ Variable[CPUIntType]{4} ] #> #> [[2]] #> tensor #> 0 #> 0 #> 0 #> 0 #> [ Variable[CPULongType]{4} ] #>
tch_mode(x, 1)
#> [[1]] #> tensor #> 1 #> 2 #> 3 #> 4 #> 5 #> [ Variable[CPUIntType]{5} ] #> #> [[2]] #> tensor #> 0 #> 0 #> 0 #> 0 #> 0 #> [ Variable[CPULongType]{5} ] #>