shift
- arrayfire.shift(array: Array, shape: tuple[int, ...], /) Array
Shifts the input ArrayFire array along each dimension by specified amounts.
This function cyclically shifts the elements of the input array along each dimension. The amount of shift for each dimension is specified in the shape tuple. A positive shift moves elements towards higher indices, while a negative shift moves them towards lower indices.
Parameters
- arrayArray
The input multi-dimensional ArrayFire array to be shifted.
- shapetuple[int, …]
A tuple specifying the amount of shift along each dimension. Can contain up to four values, corresponding to the shift along the first, second, third, and fourth dimensions, respectively. Unspecified dimensions are assumed to have a shift of 0.
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 of the same shape as array, shifted by the specified amounts along each dimension.
Examples
>>> import arrayfire as af >>> a = af.randu((3, 3)) # Generate a random 3x3 array >>> a [3 3 1 1] 0.7269 0.3569 0.3341 0.7104 0.1437 0.0899 0.5201 0.4563 0.5363
>>> b = af.shift(a, (2,)) # Shift along the first dimension by 2 >>> b [3 3 1 1] 0.7104 0.1437 0.0899 0.5201 0.4563 0.5363 0.7269 0.3569 0.3341
>>> c = af.shift(a, (1, -1)) # Shift along the first dimension by 1 and the second by -1 >>> c [3 3 1 1] 0.4563 0.5363 0.5201 0.3569 0.3341 0.7269 0.1437 0.0899 0.7104
Note
Shifts are performed cyclically, meaning that elements shifted “off” one end of the array reappear at the other.