Array

The ‘af.Array()’ class provides a powerful framework for performing high-performance numerical computations. It is designed to create an ArrayFire array from various data structures, such as Python lists or other iterable collections.

Function

af.Array()
  • Python interface to form an array.

Detailed Description

The ‘af.Array()’ object allows you to convert a data structure, such as a Python list or tuple, into an ArrayFire array. This conversion is essential for leveraging ArrayFire’s optimized computational capabilities. By creating an array from a list or another iterable, you can perform efficient mathematical operations, matrix manipulations, and other numerical computations using ArrayFire’s APIs.

It supports multiple data types and can handle multi-dimensional arrays. The ability to create an ArrayFire array from native Python structures makes it easier to integrate ArrayFire into Python-based workflows.

Function Documentation

class arrayfire.Array(obj: None | Array | array | int | AFArray | list[bool | int | float] = None, dtype: None | Dtype | str = None, shape: tuple[int, ...] = (), to_device: bool = False, offset: Type[_SimpleCData] | None = None, strides: tuple[int, ...] | None = None)

Bases: object

property H: Array

Hermitian Conjugate of the array.

Returns

Array

Two-dimensional array whose first and last dimensions (axes) are permuted in reverse order relative to | original array with its elements complex conjugated. | The returned array must have the same data type as the original array.

Note

  • The array instance must be two-dimensional. If the array instance is not two-dimensional,
    an error should be raised.
property T: Array

Transpose of the array.

Returns

Array

Two-dimensional array whose first and last dimensions (axes) are permuted in reverse order relative to original array. The returned array must have the same data type as the original array.

Note

  • The array instance must be two-dimensional. If the array instance is not two-dimensional,
    an error should be raised.
property arr: AFArray
copy() Array

Performs a deep copy of the array.

Returns

out: af.Array()

An identical copy of self.

property device: Any
property device_pointer: int
property dtype: Dtype

Data type of the array elements.

Returns

outDtype

Array data type.

classmethod from_afarray(arr: AFArray) Array

Creates an instance of Array from an AFArray object.

Parameters

array: AFArray

The array object to wrap in the Array instance.

Returns

Array

An instance of Array wrapping the given array.

property is_bool: bool
property is_column: bool
property is_complex: bool
property is_double: bool
is_empty() bool

Check if the array is empty i.e. it has no elements.

property is_floating: bool
property is_half: bool
property is_integer: bool
property is_linear: bool
property is_locked_array: bool
property is_owner: bool
property is_real: bool
property is_real_floating: bool
property is_row: bool
property is_single: bool
property is_sparse: bool
property is_vector: bool
lock_array() None
property ndim: int

Number of array dimensions (axes).

int

Number of array dimensions (axes).

property offset: int

Return the offset of the first element relative to the raw pointer.

Returns

int

The offset in number of elements.

reshape(shape) Array

Return a copy of this array with the specified shape without changing the data layout.

Parameters

shapetuple of int

The desired shape of the output array. It should be a tuple of integers representing the dimensions of the output array. The product of these dimensions must match the total number of elements in the input array.

Returns

outaf.Array
  • An array containing the same data as array with the specified shape.

  • The total number of elements in array must match the product of the dimensions
    specified in the shape tuple.

Raises

ValueError

If the total number of elements in the input array does not match the product of the dimensions specified in the shape tuple.

Notes

This function modifies the shape of the input array without changing the data layout. The resulting array will have the same data, but with a different shape as specified by the shape parameter.

scalar() int | float | bool | complex | None

Return the first element of the array

property shape: tuple[int, ...]

Array dimensions.

Returns

tuple[int, …]

Array dimensions.

property size: int

Number of elements in an array.

Returns

int

Number of elements in an array

Note

  • This must equal the product of the array’s dimensions.

property strides: tuple[int, ...]

Return the distance in bytes between consecutive elements for each dimension.

Returns

tuple[int, …]

The strides for each dimension.

to_ctype_array(row_major: bool = False) CArray
to_device(device: Any, /, *, stream: int | Any = None) Array
to_list(row_major: bool = False) list[int | float | bool | complex]
unlock_array() None