ray.data.range_tensor(n: int, *, shape: Tuple = (1,), parallelism: int = -1, concurrency: int | None = None, override_num_blocks: int | None = None) Dataset[source]#

Creates a Dataset tensors of the provided shape from range [0…n].

This function allows for easy creation of synthetic tensor datasets for testing or benchmarking Ray Data.


>>> import ray
>>> ds = ray.data.range_tensor(1000, shape=(2, 2))
>>> ds
Dataset(num_rows=1000, schema={data: numpy.ndarray(shape=(2, 2), dtype=int64)})
>>> ds.map_batches(lambda row: {"data": row["data"] * 2}).take(2)
[{'data': array([[0, 0],
       [0, 0]])}, {'data': array([[2, 2],
       [2, 2]])}]
  • n – The upper bound of the range of tensor records.

  • shape – The shape of each tensor in the dataset.

  • parallelism – This argument is deprecated. Use override_num_blocks argument.

  • concurrency – The maximum number of Ray tasks to run concurrently. Set this to control number of tasks to run concurrently. This doesn’t change the total number of tasks run or the total number of output blocks. By default, concurrency is dynamically decided based on the available resources.

  • override_num_blocks – Override the number of output blocks from all read tasks. By default, the number of output blocks is dynamically decided based on input data size and available resources. You shouldn’t manually set this value in most cases.


A Dataset producing the tensor data from range 0 to n.

See also


Call this method to create synthetic datasets of integer data.