• Finds the values and indices of the k largest entries along the last dimension.

    If the input is a vector (rank=1), finds the k largest entries in the vector and outputs their values and indices as vectors. Thus values[j] is the j-th largest entry in input, and its index is indices[j]. For higher rank inputs, computes the top k entries along the last dimension.

    If two elements are equal, the lower-index element appears first.

    const a = tf.tensor2d([[1, 5], [4, 3]]);
    const {values, indices} = tf.topk(a);
    values.print();
    indices.print();

    Type Parameters

    Parameters

    • x: TensorLike | T

      1-D or higher tf.Tensor with last dimension being at least k.

    • Optional k: number

      Number of top elements to look for along the last dimension.

    • Optional sorted: boolean

      If true, the resulting k elements will be sorted by the values in descending order.

    Returns {
        indices: T;
        values: T;
    }

    • indices: T
    • values: T

    Doc

Generated using TypeDoc