iota

arrayfire.iota(shape: int | tuple[int, ...], /, *, tile_shape: tuple[int, ...] = (), dtype: ~arrayfire_wrapper.dtypes.Dtype = arrayfire.float32(typecode<f>)) Array

Generate a multi-dimensional ArrayFire array with values populated based on their linear index within the array, optionally tiling the result to create larger arrays.

This function creates an array where each element’s value represents its linear index within the array, starting from 0. It supports optional tiling, which repeats the array across specified dimensions to create a larger array.

Parameters

shapetuple[int, …]

The shape of the array to be generated. This parameter defines the dimensions of the array. For example, shape=5 creates a 1-dimensional array of length 5, shape=(5, 4) creates a 2D array of size 5x4, and so on.

tile_shapetuple[int, …], optional, keyword-only, default: ()

The shape used for tiling the generated array. Each element in the tuple represents the number of times the array is repeated along that dimension. By default, no tiling is applied. For example, tile_shape=(2, 3) will tile the generated array 2 times along the first dimension and 3 times along the second dimension.

dtypeDtype, optional, keyword-only, default: float32

The data type of the array elements. This determines the type of the values in the generated array.

Returns

Array

A multi-dimensional ArrayFire array with elements populated based on their linear index, optionally tiled according to tile_shape.

Raises

ValueError

If shape is not int or tuple with less than one value.

Examples

>>> import arrayfire as af
>>> af.iota((3, 3))  # Generate a 3x3 array without tiling
[3 3 1 1]
    0.0000     3.0000     6.0000
    1.0000     4.0000     7.0000
    2.0000     5.0000     8.0000
>>> af.iota((3, 3), tile_shape=(1, 2))  # Generate and tile the array along the second dimension
[3 6 1 1]
    0.0000     3.0000     6.0000     0.0000     3.0000     6.0000
    1.0000     4.0000     7.0000     1.0000     4.0000     7.0000
    2.0000     5.0000     8.0000     2.0000     5.0000     8.0000