Learn R Programming

torch (version 0.0.1)

torch_kthvalue: Kthvalue

Description

Kthvalue

Arguments

input

(Tensor) the input tensor.

k

(int) k for the k-th smallest element

dim

(int, optional) the dimension to find the kth value along

keepdim

(bool) whether the output tensor has dim retained or not.

out

(tuple, optional) the output tuple of (Tensor, LongTensor) can be optionally given to be used as output buffers

kthvalue(input, k, dim=None, keepdim=False, out=None) -> (Tensor, LongTensor)

Returns a namedtuple (values, indices) where values is the k th smallest element of each row of the input tensor in the given dimension dim. And indices is the index location of each element found.

If dim is not given, the last dimension of the input is chosen.

If keepdim is True, both the values and indices tensors are the same size as input, except in the dimension dim where they are of size 1. Otherwise, dim is squeezed (see torch_squeeze), resulting in both the values and indices tensors having 1 fewer dimension than the input tensor.

Examples

Run this code
# NOT RUN {
if (torch_is_installed()) {

x = torch_arange(1., 6.)
x
torch_kthvalue(x, 4)
x=torch_arange(1.,7.)$resize_(c(2,3))
x
torch_kthvalue(x, 2, 1, TRUE)
}
# }

Run the code above in your browser using DataLab