range
- arrayfire.range(shape: int | tuple[int, ...], /, *, axis: int = 0, dtype: ~arrayfire_wrapper.dtypes.Dtype = arrayfire.float32(typecode<f>)) Array
Create a multi-dimensional array using the length of a dimension as a range.
Parameters
- shapetuple[int, …]
The shape of the resulting array. Each element represents the length of a corresponding dimension.
- axisint, optional, default: 0
The dimension along which the range is calculated.
- dtypeDtype, optional, default: float32
Data type of the array.
Returns
- Array
A multi-dimensional ArrayFire array whose elements along axis fall between [0, self.ndims[axis]-1].
Raises
- ValueError
If axis value is greater than the number of axes in resulting Array.
- ValueError
If shape is not int or tuple with less than one value.
Notes
The shape parameter determines the dimensions of the resulting array: - If shape is (x1,), the output is a 1D array of size (x1,). - If shape is (x1, x2), the output is a 2D array of size (x1, x2). - If shape is (x1, x2, x3), the output is a 3D array of size (x1, x2, x3). - If shape is (x1, x2, x3, x4), the output is a 4D array of size (x1, x2, x3, x4).
Examples
>>> import arrayfire as af >>> a = af.range((3, 2)) # axis is not specified, range is along the first dimension. >>> a # The data ranges from [0 - 2] (3 elements along the first dimension) [3 2 1 1] 0.0000 0.0000 1.0000 1.0000 2.0000 2.0000
>>> a = af.range((3, 2), axis=1) # axis is 1, range is along the second dimension. >>> a # The data ranges from [0 - 1] (2 elements along the second dimension) [3 2 1 1] 0.0000 1.0000 0.0000 1.0000 0.0000 1.0000