• Extracts a slice from a tf.Tensor starting at coordinates begin and is of size size.

    Also available are stricter rank-specific methods with the same signature as this method that assert that x is of the given rank:

    • tf.slice1d
    • tf.slice2d
    • tf.slice3d
    • tf.slice4d
    const x = tf.tensor1d([1, 2, 3, 4]);

    x.slice([1], [2]).print();
    const x = tf.tensor2d([1, 2, 3, 4], [2, 2]);

    x.slice([1, 0], [1, 2]).print();

    Type Parameters

    Parameters

    • x: TensorLike | T

      The input tf.Tensor to slice from.

    • begin: number | number[]

      The coordinates to start the slice from. The length can be less than the rank of x - the rest of the axes will have implicit 0 as start. Can also be a single number, in which case it specifies the first axis.

    • Optional size: number | number[]

      The size of the slice. The length can be less than the rank of x - the rest of the axes will have implicit -1. A value of -1 requests the rest of the dimensions in the axis. Can also be a single number, in which case it specifies the size of the first axis.

    Returns T

    Doc