Array class#
- class Array(values, dims: Tuple[Dimension, ...], spaces: Tuple[Literal['pos', 'freq'], ...], eager: Tuple[bool, ...], factors_applied: Tuple[bool, ...], xp)[source]#
The Array class facilitates the generalized Discrete Fourier transform and all operations on its values while retaining coordinate grid information.
- Parameters:
values (Any) – The values array with respect to the dimensions.
dims (Tuple[Dimension, ...]) – Dimensions defining the coordinates of the values.
spaces (Tuple[Space, ...]) – Space of the given values per Dimension.
eager (Tuple[bool, ...]) – Whether the factors should be applied to the internal values after performing a space transition. This mainly influences the behavior of
into_space
. It also acts as a tie breaker on addition and subtraction whenfactors_applied=False
andfactors_applied=True
as a result would cost equally many operations.factors_applied (Tuple[bool, ...]) – Whether the lazy factors have been applied to the given values.
xp (Any) – The array API namespace.
Examples
First, we initialize the dimensions using
fa.dim_from_constraints
:>>> import fftarray as fa >>> x_dim: fa.Dimension = fa.dim_from_constraints("x", pos_min=-1, pos_max=1., n=64, freq_middle=0.) >>> y_dim: fa.Dimension = fa.dim_from_constraints("y", pos_min=-10, pos_max=10., n=128, freq_middle=0.)
Based on these, the coordinates can be retrieved in form of 1D Arrays. These can be combined to a 2D Array via automatic broadcasting:
>>> x: fa.Array = fa.coords_from_dim(x_dim, "pos") >>> y: fa.Array = fa.coords_from_dim(y_dim, "pos") >>> xy = x**2 * fa.sin(y)
The
space
(as well as other attributes such asxp
,eager
andfactors_applied
) can be set via respective into functions:>>> xy_freq: fa.Array = xy.into_space("freq")
Integrate the Array from x=-0.2 to x=0.2 by indexing the given region before intgrating it via fa.integrate:
>>> res = fa.integrate(xy.sel(x=slice(-0.2,0.2)))
See also
Array creation functions
Elementwise functions
Manipulation functions
Statistical functions
Tools
Methods
Array.into_dtype
(dtype, /)Change the values' dtype.
Array.into_eager
(eager, /)Change the eager state.
Array.into_factors_applied
(factors_applied, /)Change the factors_applied state.
Array.into_space
(space, /)Transform the space(s) of the Array's values.
Array.into_xp
(xp, /)Change the array API namespace.
Array.isel
([indexers, missing_dims])Select specific values along respective dimension names by indices.
Array.sel
([indexers, missing_dims, method])Select specific values along respective dimension names by label/coordinate.
Array.values
(space, /, *[, xp, dtype])The raw values with all lazy fft factors applied.
Attributes
The device of the underlying array.
Tuple of the Array's Dimensions.
Dictionary mapping each dimension name to the Array's Dimension.
The dtype of the Array's values.
Whether the space transformation should be lazy or not.
Whether the lazy fft factors have been applied to the internal values.
Attribute for location based indexing like xarray.
Shape of the Array's values.
Dictionary mapping each dimension name to the number of grid points.
The spaces in which the values currently are in, per dimension.
The array API namespace driving the mathematical operations.