ComfyUI > Nodes > Basic data handling > Tensor Slice

ComfyUI Node: Tensor Slice

Class Name

TensorSlice

Category
Basic/tensor
Author
StableLlama (Account age: 861days)
Extension
Basic data handling
Latest Updated
2026-05-07
Github Stars
0.04K

How to Install Basic data handling

Install this extension via the ComfyUI Manager by searching for Basic data handling
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter Basic data handling in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Tensor Slice Description

Extracts specific tensor portions using a slice string, aiding AI artists in data manipulation.

Tensor Slice:

The TensorSlice node is designed to facilitate the extraction of specific portions of a tensor using a slice string. This node is particularly useful for AI artists who need to manipulate tensor data without delving into complex programming. By providing a simple and intuitive way to specify which parts of a tensor to extract, the TensorSlice node allows you to focus on creative tasks rather than technical details. The node interprets a slice string, which is a textual representation of the slicing operation, and applies it to the tensor, returning the desired subset. This capability is essential for tasks that require precise control over data dimensions, such as image processing or neural network input preparation.

Tensor Slice Input Parameters:

tensor

The tensor parameter is the primary data input for the TensorSlice node. It accepts any data type, but it is typically expected to be a tensor. If the input is not already a tensor, it will be converted into one. This parameter represents the multi-dimensional array from which you want to extract a specific portion. The tensor's structure and content directly influence the outcome of the slicing operation, as the slice string will be applied to this data.

slice_str

The slice_str parameter is a string that specifies how the tensor should be sliced. It uses a syntax similar to Python's slicing notation, allowing you to define start, stop, and step values for each dimension of the tensor. For example, a slice string like ":, 0:10, 5" would extract specific rows, columns, or elements from the tensor. The default value is ":", which selects the entire dimension. This parameter is crucial for determining the exact subset of the tensor you wish to work with, and understanding its syntax is key to effectively using the TensorSlice node.

Tensor Slice Output Parameters:

tensor

The output tensor is the result of applying the slice string to the input tensor. It is a new tensor that contains only the elements specified by the slice string. This output allows you to work with a focused subset of the original data, which can be particularly useful for tasks that require specific data manipulation or analysis. The sliced tensor retains the data type and device properties of the original tensor, ensuring consistency in subsequent operations.

Tensor Slice Usage Tips:

  • Use the slice string to precisely control which parts of the tensor you want to extract. Familiarize yourself with Python's slicing syntax to make the most of this feature.
  • If you're unsure about the dimensions of your tensor, consider using the TensorInfo node to retrieve its shape before applying a slice. This can help you avoid errors related to out-of-bounds indices.

Tensor Slice Common Errors and Solutions:

Failed to slice tensor with '<slice_str>': <error_message>

  • Explanation: This error occurs when the slice string is not correctly formatted or when it references indices that are out of bounds for the given tensor dimensions.
  • Solution: Double-check the slice string for syntax errors and ensure that the indices specified are within the bounds of the tensor's dimensions. Use the TensorInfo node to verify the shape of the tensor if needed.

Tensor Slice Related Nodes

Go back to the extension to check out more related nodes.
Basic data handling
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.

Tensor Slice