ttnn.arange

ttnn.arange(start: int | None = 0., end: int, step: int | None = 1., dtype: ttnn.DataType | None = ttnn.bfloat16, device: ttnn.Device | None = None, memory_config: ttnn.MemoryConfig | None = ttnn.DRAM_MEMORY_CONFIG) ttnn.Tensor

Creates a tensor with values ranging from start (inclusive) to end (exclusive) with a specified step size. The data type, device, and memory configuration of the resulting tensor can be specified.

Parameters:
  • start (int, optional) – The start of the range. Defaults to 0.

  • end (int) – The end of the range (exclusive).

  • step (int, optional) – The step size between consecutive values. Defaults to 1.

  • dtype (ttnn.DataType, optional) – The data type of the tensor. Defaults to ttnn.bfloat16.

  • device (ttnn.Device, optional) – The device where the tensor will be allocated. Defaults to None.

  • memory_config (ttnn.MemoryConfig, optional) – The memory configuration for the tensor. Defaults to ttnn.DRAM_MEMORY_CONFIG.

Returns:

ttnn.Tensor – A tensor containing evenly spaced values within the specified range.

Example

>>> tensor = ttnn.arange(start=0, end=10, step=2, dtype=ttnn.float32)
>>> print(tensor)
ttnn.Tensor([ 0.00000,  2.00000,  ...,  6.00000,  8.00000], shape=Shape([5]), dtype=DataType::FLOAT32, layout=Layout::ROW_MAJOR)