tile

arrayfire.tile(array: Array, /, shape: tuple[int, ...]) Array

Repeats an ArrayFire array along specified dimensions to create a tiled array.

This function creates a larger array by repeating the input array a specified number of times along each dimension. The amount of repetition for each dimension is specified in the shape tuple. This can be used to duplicate data along one or more axes.

Parameters

arrayArray

The input multi-dimensional ArrayFire array to be tiled.

shapetuple[int, …]

A tuple specifying the number of times the input array should be repeated along each dimension. Can contain up to four values, corresponding to the repetition factor along the first, second, third, and fourth dimensions, respectively. Dimensions not specified will not be tiled (i.e., treated as if they have a repetition factor of 1).

Raises

ValueError

If the shape tuple contains more than four elements, as only up to 4-dimensional arrays are supported.

Returns

Array

An ArrayFire array resulting from tiling the input array according to the specified shape.

Examples

>>> import arrayfire as af
>>> a = af.randu((2, 3))  # Generate a 2x3 random array
>>> a
[2 3 1 1]
    0.9508     0.2591     0.7928
    0.5367     0.8359     0.8719
>>> af.tile(a, (2,))  # Tile along the first dimension by 2
[4 3 1 1]
    0.9508     0.2591     0.7928
    0.5367     0.8359     0.8719
    0.9508     0.2591     0.7928
    0.5367     0.8359     0.8719
>>> af.tile(a, (1, 2))  # Tile along the second dimension by 2
[2 6 1 1]
    0.9508     0.2591     0.7928     0.9508     0.2591     0.7928
    0.5367     0.8359     0.8719     0.5367     0.8359     0.8719
>>> af.tile(a, (2, 2))  # Tile both dimensions by 2
[4 6 1 1]
    0.9508     0.2591     0.7928     0.9508     0.2591     0.7928
    0.5367     0.8359     0.8719     0.5367     0.8359     0.8719
    0.9508     0.2591     0.7928     0.9508     0.2591     0.7928
    0.5367     0.8359     0.8719     0.5367     0.8359     0.8719

Note

  • The repetition factor of 1 means the dimension is not tiled.