Array creation functions

Array creation functions#

array(values, dim: Dimension | Iterable[Dimension], space: Literal['pos', 'freq'] | Iterable[Literal['pos', 'freq']], /, *, xp: Any | None = None, dtype: Any | None = None, device: Any | None = None, defensive_copy: bool = True) Array[source]#

Construct a new instance of Array from raw values.

Parameters:
  • values – The values to initialize the Array with. They can be of any Python Arrray API v2023.12 compatible library. By default they are copied to make sure an external alias cannot influence the created Array.

  • dim (Union[Dimension, Iterable[Dimension]]) – The Dimension(s) for each dimension of the passed in values.

  • space (Union[Space, Iterable[Space]]) – Specify the space(s) of the values with which the returned Array intialized.

  • xp (Optional[Any]) – The Array API namespace to use for the created Array. If it is None, array_api_compat.array_namespace(values) is used. If that fails the default namespace from get_default_xp() is used.

  • dtype (Optional[Any]) – Directly passed on to the xp.asarray of the determined xp. If None the dtype of values or the defaults for the passed in scalar of the underlying array library are used.

  • defensive_copy (bool) – If True the values array is always copied in order to ensure no external alias to it exists. This ensures the immutability of the created Array. If this is unnecessary, this defensive copy can be prevented by setting this argument to False. In this case it has to be ensured that the passed in array is not used externally after creation.

  • device (Any | None)

Return type:

Array

See also

set_default_eager, get_default_eager, Array

coords_from_arr(x: Array, dim_name: str, space: Literal['pos', 'freq'], /, *, xp: Any | None = None, dtype: Any | None = None, device: Any | None = None) Array[source]#

Constructs an array filled with the coordinates of the specified dimension while keeping all other attributes (Array API namespace, eager) of the specified array.

Parameters:
  • x (Array) – The array from which to construct the coordinate array.

  • space (Space) – Specify the space of the returned Array is intialized.

  • dim_name (str) – The name of the dimension from which to construct the coordinate array.

  • xp (Optional[Any]) – The array namespace to use for the returned Array. None uses the array namespace of x.

  • dtype (Optional[Any]) – The dtype to use for the created coordinate array. None uses a real floating point type with the same precision as x.

  • device (Any | None)

Returns:

The grid coordinates of the chosen space packed into an Array with the dimension of name dim_name. eager of the created array is the same as eager in the selected dimension of x.

Return type:

Array

coords_from_dim(dim: Dimension, space: Literal['pos', 'freq'], /, *, xp: Any | None = None, dtype: Any | None = None, device: Any | None = None) Array[source]#
Parameters:
  • dim (Dimension) – The dimension from which the coordinate grid should be created.

  • space (Space) – Specify the space of the coordinates and in which space the returned Array is intialized.

  • xp (Optional[Any]) – The array namespace to use for the returned Array. None uses default numpy which can be globally changed.

  • dtype (Optional[Any]) – The dtype to use for the returned Array. None uses the default floating point type of the chosen xp.

  • device (Any | None)

Returns:

The grid coordinates of the chosen space packed into an Array with self as only dimension.

Return type:

Array

full(dim: Dimension | Iterable[Dimension], space: Literal['pos', 'freq'] | Iterable[Literal['pos', 'freq']], fill_value: bool | int | float | complex | Any, /, *, xp: Any | None = None, dtype: Any | None = None, device: Any | None = None) Array[source]#
Parameters:
  • dim (Union[Dimension, Iterable[Dimension]]) – The dimension(s) of the created array. They also imply the shape.

  • space (Union[Space, Iterable[Space]]) – Specify the space(s) in which the returned Array is intialized.

  • xp (Any | None) – The Array API namespace to use for the created Array. If it is None, array_api_compat.array_namespace(fill_value) is used. If that fails the default namespace from get_default_xp() is used.

  • dtype (Optional[Any]) – The dtype to use for the returned Array. If the value is None, the dtype is inferred from fill_value according to the rules of the underlying Array API.

  • fill_value (bool | int | float | complex | Any)

  • device (Any | None)

Returns:

The grid coordinates of the chosen space packed into an Array with self as only dimension.

Return type:

Array