glass.arraytools — Array tools utilities¶
This module contains utilities for working with arrays which are used by GLASS.
This module should be imported manually if used outside of GLASS:
import glass.arraytools
General¶
- glass.arraytools.broadcast_first(*arrays)[source]¶
Broadcast arrays, treating the first axis as common.
- glass.arraytools.broadcast_leading_axes(*args, xp=None)[source]¶
Broadcast all but the last N axes.
- Parameters:
args (tuple[float | FloatArray, int]) – The arrays and the number of axes to keep.
xp (ModuleType | None) – The array library backend to use for array operations.
- Returns:
The shape of the broadcast dimensions, and all input arrays with leading axes matching that shape.
- Return type:
tuple[tuple[int, …], *tuple[FloatArray, …]]
Examples
Broadcast all dimensions of
a, all except the last dimension ofb, and all except the last two dimensions ofc.>>> import numpy as np >>> a = 0 >>> b = np.zeros((4, 10)) >>> c = np.zeros((3, 1, 5, 6)) >>> dims, a, b, c = broadcast_leading_axes((a, 0), (b, 1), (c, 2)) >>> dims (3, 4) >>> a.shape (3, 4) >>> b.shape (3, 4, 10) >>> c.shape (3, 4, 5, 6)
- glass.arraytools.cumulative_trapezoid(f, x)[source]¶
Cumulative trapezoidal rule along last axis.
- Parameters:
f (IntArray | FloatArray) – The function values.
x (IntArray | FloatArray) – The x-coordinates.
- Returns:
The cumulative integral of the function.
- Return type:
AnyArray
- glass.arraytools.ndinterp(x, xq, fq, axis=-1, left=None, right=None, period=None)[source]¶
Interpolate multi-dimensional array over axis.
- Parameters:
x (float | FloatArray) – The x-coordinates.
xq (FloatArray) – The x-coordinates of the data points.
fq (FloatArray) – The function values corresponding to the x-coordinates in xq.
axis (int) – The axis to interpolate over.
left (float | None) – The value to return for x < xq[0].
right (float | None) – The value to return for x > xq[-1].
period (float | None) – The period of the function, used for interpolating periodic data.
- Returns:
The interpolated array.
- Return type:
FloatArray
- glass.arraytools.trapezoid_product(f, *ff, axis=-1)[source]¶
Trapezoidal rule for a product of functions.
- Parameters:
f (tuple[FloatArray, FloatArray]) – The first function.
ff (tuple[FloatArray, FloatArray]) – The other functions.
axis (int) – The axis along which to integrate.
- Returns:
The integral of the product of the functions.
- Return type:
float | FloatArray