CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-awkward

Manipulate JSON-like data with NumPy-like idioms for scientific computing and high-energy physics.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

mathematical-operations.mddocs/

Mathematical and Statistical Operations

Full suite of mathematical operations including reductions, element-wise functions, linear algebra, and statistical analysis that handle missing data and nested structures appropriately. These operations extend NumPy's capabilities to work seamlessly with irregular, nested data.

Capabilities

Reduction Operations

Functions that reduce arrays along specified axes, properly handling variable-length lists and missing values to compute aggregate statistics.

def sum(array, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None):
    """
    Sum array elements along specified axis.
    
    Parameters:
    - array: Array-like data to sum
    - axis: int or None, axis along which to sum (None for all axes)
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if False return identity (0) for empty sequences, if True return None
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing sums along specified axis
    """

def prod(array, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None):
    """
    Product of array elements along specified axis.
    
    Parameters:
    - array: Array to compute product of
    - axis: int or None, axis along which to compute product
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if False return identity (1) for empty sequences, if True return None
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing products along specified axis
    """

def count(array, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None):
    """
    Count non-None elements along specified axis.
    
    Parameters:
    - array: Array to count elements in
    - axis: int or None, axis along which to count
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if False return identity (0) for empty sequences, if True return None
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing counts of non-None elements
    """

def count_nonzero(array, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None):
    """
    Count non-zero elements along specified axis.
    
    Parameters:
    - array: Array to count non-zero elements in
    - axis: int or None, axis along which to count
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if False return identity (0) for empty sequences, if True return None
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing counts of non-zero elements
    """

def any(array, axis=None, keepdims=False, mask_identity=True):
    """
    Test if any elements along axis evaluate to True.
    
    Parameters:
    - array: Array to test
    - axis: int or None, axis along which to test
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if True return None for empty sequences
    
    Returns:
    Array of booleans indicating if any elements are True
    """

def all(array, axis=None, keepdims=False, mask_identity=True):
    """
    Test if all elements along axis evaluate to True.
    
    Parameters:
    - array: Array to test
    - axis: int or None, axis along which to test
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if True return None for empty sequences
    
    Returns:
    Array of booleans indicating if all elements are True
    """

Min/Max Operations

Functions for finding minimum and maximum values and their positions, with support for NaN handling and proper treatment of empty sequences.

def min(array, axis=None, *, keepdims=False, initial=None, mask_identity=True, highlevel=True, behavior=None, attrs=None):
    """
    Find minimum values along specified axis.
    
    Parameters:
    - array: Array to find minimum in
    - axis: int or None, axis along which to find minimum
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - initial: value, initial value for minimum search
    - mask_identity: bool, if True return None for empty sequences
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing minimum values along specified axis
    """

def max(array, axis=None, *, keepdims=False, initial=None, mask_identity=True, highlevel=True, behavior=None, attrs=None):
    """
    Find maximum values along specified axis.
    
    Parameters:
    - array: Array to find maximum in
    - axis: int or None, axis along which to find maximum
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - initial: value, initial value for maximum search
    - mask_identity: bool, if True return None for empty sequences
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing maximum values along specified axis
    """

def argmin(array, axis=None, *, keepdims=False, mask_identity=True, highlevel=True, behavior=None, attrs=None):
    """
    Find indices of minimum values along specified axis.
    
    Parameters:
    - array: Array to find minimum indices in
    - axis: int or None, axis along which to find argmin
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if True return None for empty sequences
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing indices of minimum values
    """

def argmax(array, axis=None, *, keepdims=False, mask_identity=True, highlevel=True, behavior=None, attrs=None):
    """
    Find indices of maximum values along specified axis.
    
    Parameters:
    - array: Array to find maximum indices in
    - axis: int or None, axis along which to find argmax
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if True return None for empty sequences
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing indices of maximum values
    """

def nanmin(array, axis=None, keepdims=False, mask_identity=True):
    """
    Find minimum values ignoring NaN along specified axis.
    
    Parameters:
    - array: Array to find minimum in
    - axis: int or None, axis along which to find minimum
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if True return None for empty sequences
    
    Returns:
    Array containing minimum values ignoring NaN
    """

def nanmax(array, axis=None, keepdims=False, mask_identity=True):
    """
    Find maximum values ignoring NaN along specified axis.
    
    Parameters:
    - array: Array to find maximum in
    - axis: int or None, axis along which to find maximum
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if True return None for empty sequences
    
    Returns:
    Array containing maximum values ignoring NaN
    """

def nanargmin(array, axis=None, keepdims=False, mask_identity=True):
    """
    Find indices of minimum values ignoring NaN.
    
    Parameters:
    - array: Array to find minimum indices in
    - axis: int or None, axis along which to find argmin
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if True return None for empty sequences
    
    Returns:
    Array containing indices of minimum values ignoring NaN
    """

def nanargmax(array, axis=None, keepdims=False, mask_identity=True):
    """
    Find indices of maximum values ignoring NaN.
    
    Parameters:
    - array: Array to find maximum indices in
    - axis: int or None, axis along which to find argmax
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if True return None for empty sequences
    
    Returns:
    Array containing indices of maximum values ignoring NaN
    """

def ptp(array, axis=None, keepdims=False, mask_identity=True):
    """
    Range (peak-to-peak) along specified axis.
    
    Parameters:
    - array: Array to compute range for
    - axis: int or None, axis along which to compute range
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if True return None for empty sequences
    
    Returns:
    Array containing range (max - min) along specified axis
    """

Statistical Functions

Comprehensive statistical operations including moments, variance, standard deviation, and correlation analysis with proper handling of nested data structures.

def mean(x, weight=None, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None):
    """
    Arithmetic mean along specified axis.
    
    Parameters:
    - x: Array to compute mean of
    - weight: Array, optional weights for weighted mean
    - axis: int or None, axis along which to compute mean
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if False return identity (0) for empty sequences, if True return None
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing arithmetic mean along specified axis
    """

def var(x, weight=None, ddof=0, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None):
    """
    Variance along specified axis.
    
    Parameters:
    - x: Array to compute variance of
    - weight: Array, optional weights for weighted variance
    - ddof: int, delta degrees of freedom for denominator
    - axis: int or None, axis along which to compute variance
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if False return identity (0) for empty sequences, if True return None
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing variance along specified axis
    """

def std(x, weight=None, ddof=0, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None):
    """
    Standard deviation along specified axis.
    
    Parameters:
    - x: Array to compute standard deviation of
    - weight: Array, optional weights for weighted standard deviation
    - ddof: int, delta degrees of freedom for denominator
    - axis: int or None, axis along which to compute std dev
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if False return identity (0) for empty sequences, if True return None
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing standard deviation along specified axis
    """

def moment(array, n, axis=None, keepdims=False, mask_identity=True):
    """
    Calculate the nth moment about the mean.
    
    Parameters:
    - array: Array to compute moment of
    - n: int, order of the moment
    - axis: int or None, axis along which to compute moment
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if True return None for empty sequences
    
    Returns:
    Array containing nth moment along specified axis
    """

def nansum(array, axis=None, keepdims=False):
    """
    Sum ignoring NaN values along specified axis.
    
    Parameters:
    - array: Array to sum
    - axis: int or None, axis along which to sum
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    
    Returns:
    Array containing sums ignoring NaN values
    """

def nanprod(array, axis=None, keepdims=False):
    """
    Product ignoring NaN values along specified axis.
    
    Parameters:
    - array: Array to compute product of
    - axis: int or None, axis along which to compute product
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    
    Returns:
    Array containing products ignoring NaN values
    """

def nanmean(array, axis=None, keepdims=False):
    """
    Arithmetic mean ignoring NaN values.
    
    Parameters:
    - array: Array to compute mean of
    - axis: int or None, axis along which to compute mean
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    
    Returns:
    Array containing arithmetic mean ignoring NaN values
    """

def nanvar(array, axis=None, ddof=0, keepdims=False):
    """
    Variance ignoring NaN values.
    
    Parameters:
    - array: Array to compute variance of
    - axis: int or None, axis along which to compute variance
    - ddof: int, delta degrees of freedom for denominator
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    
    Returns:
    Array containing variance ignoring NaN values
    """

def nanstd(array, axis=None, ddof=0, keepdims=False):
    """
    Standard deviation ignoring NaN values.
    
    Parameters:
    - array: Array to compute standard deviation of
    - axis: int or None, axis along which to compute std dev
    - ddof: int, delta degrees of freedom for denominator
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    
    Returns:
    Array containing standard deviation ignoring NaN values
    """

Linear Algebra and Regression

Functions for linear algebra operations and statistical modeling on nested data structures.

def linear_fit(x, y, weight=None, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None):
    """
    Perform linear regression fit.
    
    Parameters:
    - x: Array of independent variable values
    - y: Array of dependent variable values
    - weight: Array, optional weights for weighted regression
    - axis: int or None, axis along which to perform regression
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if False return identity for empty sequences, if True return None
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing regression parameters (intercept, slope)
    """

def corr(x, y, weight=None, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None):
    """
    Calculate Pearson correlation coefficient.
    
    Parameters:
    - x: Array of first variable values
    - y: Array of second variable values
    - weight: Array, optional weights for weighted correlation
    - axis: int or None, axis along which to compute correlation
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if False return identity for empty sequences, if True return None
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing correlation coefficients
    """

def covar(x, y, weight=None, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None):
    """
    Calculate covariance.
    
    Parameters:
    - x: Array of first variable values
    - y: Array of second variable values
    - weight: Array, optional weights for weighted covariance
    - axis: int or None, axis along which to compute covariance
    - keepdims: bool, if True keep reduced axes as size-one dimensions
    - mask_identity: bool, if False return identity for empty sequences, if True return None
    - highlevel: bool, if True return Array, if False return Content layout
    - behavior: dict, custom behavior for the result
    - attrs: dict, metadata attributes for the result
    
    Returns:
    Array containing covariance values
    """

Complex Number Operations

Mathematical functions specifically for complex number arrays, including component extraction and phase calculations.

def real(array):
    """
    Extract real part of complex numbers.
    
    Parameters:
    - array: Array of complex numbers
    
    Returns:
    Array containing real parts
    """

def imag(array):
    """
    Extract imaginary part of complex numbers.
    
    Parameters:
    - array: Array of complex numbers
    
    Returns:
    Array containing imaginary parts
    """

def angle(array, deg=False):
    """
    Calculate phase angle of complex numbers.
    
    Parameters:
    - array: Array of complex numbers
    - deg: bool, if True return angles in degrees (default radians)
    
    Returns:
    Array containing phase angles
    """

Special Mathematical Functions

Specialized mathematical operations including rounding, special value handling, and activation functions.

def round(array, decimals=0):
    """
    Round array elements to specified number of decimals.
    
    Parameters:
    - array: Array to round
    - decimals: int, number of decimal places to round to
    
    Returns:
    Array with rounded values
    """

def nan_to_none(array):
    """
    Convert NaN values to None.
    
    Parameters:
    - array: Array to convert
    
    Returns:
    Array with NaN values replaced by None
    """

def nan_to_num(array, nan=0.0, posinf=None, neginf=None):
    """
    Convert NaN and infinity values to finite numbers.
    
    Parameters:
    - array: Array to convert
    - nan: float, value to replace NaN with
    - posinf: float, value to replace positive infinity with
    - neginf: float, value to replace negative infinity with
    
    Returns:
    Array with special values replaced by finite numbers
    """

def softmax(array, axis=None):
    """
    Compute softmax activation function.
    
    Parameters:
    - array: Array to apply softmax to
    - axis: int or None, axis along which to compute softmax
    
    Returns:
    Array with softmax values (probabilities summing to 1)
    """

Array Comparison and Equality

Functions for comparing arrays and testing approximate equality with appropriate handling of nested structures and missing values.

def array_equal(a, b, check_parameters=True, check_type=True):
    """
    Test if two arrays are exactly equal.
    
    Parameters:
    - a: First Array to compare
    - b: Second Array to compare
    - check_parameters: bool, if True compare type parameters
    - check_type: bool, if True compare type information
    
    Returns:
    bool indicating if arrays are equal
    """

def almost_equal(a, b, rtol=1e-05, atol=1e-08, check_parameters=True, check_type=True):
    """
    Test if two arrays are approximately equal.
    
    Parameters:
    - a: First Array to compare
    - b: Second Array to compare
    - rtol: float, relative tolerance
    - atol: float, absolute tolerance
    - check_parameters: bool, if True compare type parameters
    - check_type: bool, if True compare type information
    
    Returns:
    bool indicating if arrays are approximately equal
    """

def isclose(a, b, rtol=1e-05, atol=1e-08):
    """
    Element-wise test for approximate equality.
    
    Parameters:
    - a: First Array to compare
    - b: Second Array to compare
    - rtol: float, relative tolerance
    - atol: float, absolute tolerance
    
    Returns:
    Array of booleans indicating element-wise approximate equality
    """

Sorting and Ordering

Functions for sorting array elements and finding element positions, with proper handling of nested structures.

def sort(array, axis=-1, ascending=True, stable=True):
    """
    Sort array elements along specified axis.
    
    Parameters:
    - array: Array to sort
    - axis: int, axis along which to sort
    - ascending: bool, if True sort in ascending order
    - stable: bool, if True use stable sorting algorithm
    
    Returns:
    Array with sorted elements
    """

def argsort(array, axis=-1, ascending=True, stable=True):
    """
    Get indices that would sort array along specified axis.
    
    Parameters:
    - array: Array to get sort indices for
    - axis: int, axis along which to sort
    - ascending: bool, if True sort in ascending order
    - stable: bool, if True use stable sorting algorithm
    
    Returns:
    Array containing indices that sort the input array
    """

def local_index(array, axis=-1):
    """
    Get local position indices within each list.
    
    Parameters:
    - array: Array to get local indices for
    - axis: int, axis along which to compute local indices
    
    Returns:
    Array containing local position indices (0, 1, 2, ... within each list)
    """

def run_lengths(array):
    """
    Compute run-length encoding of array.
    
    Parameters:
    - array: Array to compute run lengths for
    
    Returns:
    tuple of (values, lengths) arrays representing run-length encoding
    """

Usage Examples

Basic Reductions

import awkward as ak

# Nested data with variable-length lists
data = ak.Array([[1, 2, 3], [4], [5, 6, 7, 8]])

# Sum along inner axis (sum each list)
inner_sums = ak.sum(data, axis=1)  # [6, 4, 26]

# Sum all elements
total = ak.sum(data)  # 36

# Count elements in each list
counts = ak.count(data, axis=1)  # [3, 1, 4]

# Mean of each list
means = ak.mean(data, axis=1)  # [2.0, 4.0, 6.5]

Statistical Analysis

import awkward as ak
import numpy as np

# Data with some missing values
data = ak.Array([[1.0, 2.0, np.nan], [4.0], [5.0, 6.0, 7.0]])

# Standard statistics
std_devs = ak.std(data, axis=1)  # Standard deviation per list
variances = ak.var(data, axis=1)  # Variance per list

# NaN-aware operations
nan_means = ak.nanmean(data, axis=1)  # [1.5, 4.0, 6.0]
nan_sums = ak.nansum(data, axis=1)   # [3.0, 4.0, 18.0]

Complex Operations

import awkward as ak

# Record data
records = ak.Array([
    {"pt": [10.0, 20.0, 15.0], "eta": [1.0, -0.5, 2.0]},
    {"pt": [25.0, 30.0], "eta": [0.0, 1.5]}
])

# Cross-field operations
pt_eta_corr = ak.corr(records.pt, records.eta, axis=1)

# Min/max across fields
min_pt = ak.min(records.pt, axis=1)  # [10.0, 25.0]
max_eta = ak.max(records.eta, axis=1)  # [2.0, 1.5]

Comparisons and Sorting

import awkward as ak

data = ak.Array([[3, 1, 4], [2], [1, 5, 9, 2]])

# Sort each list
sorted_data = ak.sort(data, axis=1)  # [[1, 3, 4], [2], [1, 2, 5, 9]]

# Get sort indices
sort_indices = ak.argsort(data, axis=1)  # [[1, 0, 2], [0], [0, 3, 1, 2]]

# Array comparison
other = ak.Array([[3, 1, 4], [2], [1, 5, 9, 2]])
are_equal = ak.array_equal(data, other)  # True

Install with Tessl CLI

npx tessl i tessl/pypi-awkward

docs

array-creation.md

array-manipulation.md

data-conversion.md

index.md

integration.md

mathematical-operations.md

string-operations.md

type-system.md

tile.json