Parallel PyData with task scheduling for distributed analytics and computing.
—
NumPy-compatible distributed arrays for parallel and out-of-core computation. Dask arrays break large arrays into chunks and operate on them in parallel, providing the NumPy interface while scaling beyond memory limits.
import dask.array as da
from dask.array import (
# Core array creation and manipulation
array, asarray, asanyarray, from_array,
zeros, ones, empty, full, zeros_like, ones_like, empty_like, full_like,
arange, linspace, logspace, geomspace, eye, diag, diagonal, indices, meshgrid,
# Mathematical operations
add, subtract, multiply, divide, power, sqrt, sin, cos, tan, exp, log,
# Linear algebra (also available as da.linalg)
dot, matmul, tensordot, einsum, outer, inner, vdot,
# Reductions and aggregations
sum, mean, std, var, min, max, argmin, argmax, all, any, prod,
nansum, nanmean, nanstd, nanvar, nanmin, nanmax, nanprod,
# Array manipulation
reshape, transpose, concatenate, stack, split, flip, roll,
# Advanced operations
map_blocks, blockwise, apply_along_axis, apply_gufunc,
# I/O operations
store, to_zarr, from_zarr, to_hdf5, from_npy_stack, to_npy_stack
)
# Submodules
import dask.array.linalg as da_linalg
import dask.array.fft as da_fft
import dask.array.random as da_randomCreate Dask arrays from various sources including existing arrays, functions, and file formats.
def array(object, dtype=None, chunks=None, name=None, meta=None):
"""
Create dask array from array-like object.
Parameters:
- object: Array-like object to convert
- dtype: Data type for the array
- chunks: Chunk size specification
- name: Custom name for array in task graph
- meta: Metadata array for type inference
Returns:
dask.array.Array: Dask array
"""
def from_array(x, chunks=None, name=None, lock=False, asarray=None,
fancy=True, getitem=None, meta=None):
"""
Create dask array from existing array with specified chunking.
Parameters:
- x: Existing array-like object
- chunks: Chunk size specification (int, tuple, or 'auto')
- name: Custom name for array
- lock: Thread lock for thread-unsafe arrays
- asarray: Function to convert chunks to arrays
- fancy: Support advanced indexing
- getitem: Custom getitem function
- meta: Metadata array
Returns:
dask.array.Array: Chunked dask array
"""
def asarray(a, chunks=None, name=None, dtype=None, **kwargs):
"""
Convert input to dask array.
Parameters:
- a: Input array-like object
- chunks: Chunk specification
- name: Array name
- dtype: Data type
- **kwargs: Additional arguments
Returns:
dask.array.Array: Dask array
"""
def asanyarray(a, chunks=None, name=None, dtype=None, **kwargs):
"""
Convert input to dask array, preserving subclasses.
Parameters:
- a: Input array-like object
- chunks: Chunk specification
- name: Array name
- dtype: Data type
- **kwargs: Additional arguments
Returns:
dask.array.Array: Dask array
"""Standard array creation functions similar to NumPy.
def zeros(shape, dtype=float, chunks=None, **kwargs):
"""Create array filled with zeros."""
def ones(shape, dtype=float, chunks=None, **kwargs):
"""Create array filled with ones."""
def full(shape, fill_value, dtype=None, chunks=None, **kwargs):
"""Create array filled with specified value."""
def empty(shape, dtype=float, chunks=None, **kwargs):
"""Create uninitialized array."""
def zeros_like(a, dtype=None, chunks=None, **kwargs):
"""Create zeros array with same shape as input."""
def ones_like(a, dtype=None, chunks=None, **kwargs):
"""Create ones array with same shape as input."""
def full_like(a, fill_value, dtype=None, chunks=None, **kwargs):
"""Create filled array with same shape as input."""
def empty_like(a, dtype=None, chunks=None, **kwargs):
"""Create empty array with same shape as input."""Create arrays with numeric sequences and patterns.
def arange(start, stop=None, step=None, chunks=None, dtype=None, **kwargs):
"""
Create array with evenly spaced values.
Parameters:
- start: Start value or stop if only one argument
- stop: End value (exclusive)
- step: Step between values
- chunks: Chunk specification
- dtype: Data type
Returns:
dask.array.Array: Array with range values
"""
def linspace(start, stop, num=50, endpoint=True, retstep=False,
chunks=None, dtype=None):
"""
Create array with linearly spaced values.
Parameters:
- start: Start value
- stop: End value
- num: Number of samples
- endpoint: Include stop value
- retstep: Return step size
- chunks: Chunk specification
- dtype: Data type
Returns:
dask.array.Array or tuple: Array and optionally step size
"""
def logspace(start, stop, num=50, endpoint=True, base=10.0,
chunks=None, dtype=None):
"""
Create array with logarithmically spaced values.
Parameters:
- start: Start value (base**start)
- stop: End value (base**stop)
- num: Number of samples
- endpoint: Include stop value
- base: Base of logarithm
- chunks: Chunk specification
- dtype: Data type
Returns:
dask.array.Array: Array with log-spaced values
"""
def geomspace(start, stop, num=50, endpoint=True, chunks=None, dtype=None):
"""
Create array with geometrically spaced values.
Parameters:
- start: Start value
- stop: End value
- num: Number of samples
- endpoint: Include stop value
- chunks: Chunk specification
- dtype: Data type
Returns:
dask.array.Array: Array with geometrically spaced values
"""
def eye(N, M=None, k=0, dtype=float, chunks=None, **kwargs):
"""
Create identity matrix.
Parameters:
- N: Number of rows
- M: Number of columns (defaults to N)
- k: Diagonal offset (0=main diagonal)
- dtype: Data type
- chunks: Chunk specification
Returns:
dask.array.Array: Identity matrix
"""
def diag(v, k=0, chunks=None, **kwargs):
"""
Create diagonal array or extract diagonal.
Parameters:
- v: Input array or diagonal values
- k: Diagonal offset
- chunks: Chunk specification
Returns:
dask.array.Array: Diagonal array or extracted diagonal
"""
def diagonal(a, offset=0, axis1=0, axis2=1):
"""
Extract diagonal from array.
Parameters:
- a: Input array
- offset: Diagonal offset
- axis1: First axis
- axis2: Second axis
Returns:
dask.array.Array: Diagonal elements
"""
def indices(dimensions, dtype=int, chunks=None):
"""
Return coordinate arrays for given dimensions.
Parameters:
- dimensions: Shape of output arrays
- dtype: Data type for coordinates
- chunks: Chunk specification
Returns:
dask.array.Array: Grid coordinate arrays
"""
def meshgrid(*xi, copy=True, sparse=False, indexing='xy', chunks=None):
"""
Return coordinate matrices from coordinate vectors.
Parameters:
- *xi: Input coordinate vectors
- copy: Copy input arrays
- sparse: Return sparse grid
- indexing: Cartesian ('xy') or matrix ('ij') indexing
- chunks: Chunk specification
Returns:
tuple of dask.array.Array: Coordinate matrices
"""
def tri(N, M=None, k=0, dtype=float, chunks=None):
"""
Create array with ones on and below diagonal.
Parameters:
- N: Number of rows
- M: Number of columns (defaults to N)
- k: Diagonal offset
- dtype: Data type
- chunks: Chunk specification
Returns:
dask.array.Array: Lower triangular array
"""
def tril(m, k=0):
"""
Lower triangle of array.
Parameters:
- m: Input array
- k: Diagonal offset
Returns:
dask.array.Array: Lower triangular array
"""
def triu(m, k=0):
"""
Upper triangle of array.
Parameters:
- m: Input array
- k: Diagonal offset
Returns:
dask.array.Array: Upper triangular array
"""Core Array class with essential properties and methods.
class Array:
"""
N-dimensional distributed array with NumPy interface.
Properties:
- shape: tuple - Array dimensions
- dtype: numpy.dtype - Data type
- ndim: int - Number of dimensions
- size: int - Total number of elements
- chunks: tuple - Chunk sizes per dimension
- npartitions: int - Total number of chunks
- nbytes: int - Total bytes of array
"""
def compute(self, scheduler=None, **kwargs):
"""
Compute array and return NumPy result.
Parameters:
- scheduler: Scheduler to use
- **kwargs: Additional compute arguments
Returns:
numpy.ndarray: Computed array
"""
def persist(self, scheduler=None, **kwargs):
"""
Persist array in memory for reuse.
Parameters:
- scheduler: Scheduler to use
- **kwargs: Additional persist arguments
Returns:
dask.array.Array: Persisted array
"""
def rechunk(self, chunks=None, threshold=None, block_size_limit=None,
balance=False):
"""
Change array chunking.
Parameters:
- chunks: New chunk specification
- threshold: Rechunk threshold
- block_size_limit: Maximum chunk size
- balance: Balance chunk sizes
Returns:
dask.array.Array: Rechunked array
"""
def __getitem__(self, key):
"""Array indexing and slicing."""
def __array_ufunc__(self, numpy_ufunc, method, *inputs, **kwargs):
"""NumPy universal function interface."""Mathematical functions and operations following NumPy conventions.
# Arithmetic operations
def add(x1, x2, **kwargs):
"""
Add arrays element-wise.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise sum
"""
def subtract(x1, x2, **kwargs):
"""
Subtract arrays element-wise.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise difference
"""
def multiply(x1, x2, **kwargs):
"""
Multiply arrays element-wise.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise product
"""
def divide(x1, x2, **kwargs):
"""
Divide arrays element-wise.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise division
"""
def true_divide(x1, x2, **kwargs):
"""
True division element-wise (always returns float).
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise true division
"""
def floor_divide(x1, x2, **kwargs):
"""
Floor division element-wise.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise floor division
"""
def power(x1, x2, **kwargs):
"""
Raise first array to powers from second array.
Parameters:
- x1: Base array
- x2: Exponent array
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise powers
"""
def float_power(x1, x2, **kwargs):
"""
Raise first array to powers (always returns float).
Parameters:
- x1: Base array
- x2: Exponent array
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise powers as float
"""
def mod(x1, x2, **kwargs):
"""
Modulo operation element-wise.
Parameters:
- x1: Dividend array
- x2: Divisor array
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise remainder
"""
def remainder(x1, x2, **kwargs):
"""
Remainder operation element-wise (alias for mod).
Parameters:
- x1: Dividend array
- x2: Divisor array
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise remainder
"""
def divmod(x1, x2, **kwargs):
"""
Simultaneous floor division and modulo.
Parameters:
- x1: Dividend array
- x2: Divisor array
- **kwargs: Additional ufunc parameters
Returns:
tuple: (quotient, remainder) arrays
"""
def negative(x, **kwargs):
"""
Numerical negative element-wise.
Parameters:
- x: Input array
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise negative
"""
def positive(x, **kwargs):
"""
Numerical positive element-wise.
Parameters:
- x: Input array
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise positive
"""
def absolute(x, **kwargs):
"""
Absolute value element-wise.
Parameters:
- x: Input array
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Element-wise absolute value
"""
def abs(x, **kwargs):
"""Alias for absolute."""
# Comparison operations
def equal(x1, x2, **kwargs):
"""
Element-wise equality comparison.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Boolean array of equality
"""
def not_equal(x1, x2, **kwargs):
"""
Element-wise inequality comparison.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Boolean array of inequality
"""
def less(x1, x2, **kwargs):
"""
Element-wise less-than comparison.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Boolean array of x1 < x2
"""
def less_equal(x1, x2, **kwargs):
"""
Element-wise less-than-or-equal comparison.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Boolean array of x1 <= x2
"""
def greater(x1, x2, **kwargs):
"""
Element-wise greater-than comparison.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Boolean array of x1 > x2
"""
def greater_equal(x1, x2, **kwargs):
"""
Element-wise greater-than-or-equal comparison.
Parameters:
- x1, x2: Input arrays
- **kwargs: Additional ufunc parameters
Returns:
dask.array.Array: Boolean array of x1 >= x2
"""
# Trigonometric functions
def sin(x, **kwargs):
"""Trigonometric sine element-wise."""
def cos(x, **kwargs):
"""Trigonometric cosine element-wise."""
def tan(x, **kwargs):
"""Trigonometric tangent element-wise."""
def arcsin(x, **kwargs):
"""Inverse sine element-wise."""
def arccos(x, **kwargs):
"""Inverse cosine element-wise."""
def arctan(x, **kwargs):
"""Inverse tangent element-wise."""
def arctan2(y, x, **kwargs):
"""Element-wise arc tangent of y/x in correct quadrant."""
def degrees(x, **kwargs):
"""Convert angles from radians to degrees."""
def radians(x, **kwargs):
"""Convert angles from degrees to radians."""
def deg2rad(x, **kwargs):
"""Convert degrees to radians (alias for radians)."""
def rad2deg(x, **kwargs):
"""Convert radians to degrees (alias for degrees)."""
# Hyperbolic functions
def sinh(x, **kwargs):
"""Hyperbolic sine element-wise."""
def cosh(x, **kwargs):
"""Hyperbolic cosine element-wise."""
def tanh(x, **kwargs):
"""Hyperbolic tangent element-wise."""
def arcsinh(x, **kwargs):
"""Inverse hyperbolic sine element-wise."""
def arccosh(x, **kwargs):
"""Inverse hyperbolic cosine element-wise."""
def arctanh(x, **kwargs):
"""Inverse hyperbolic tangent element-wise."""
# Exponential and logarithmic functions
def exp(x, **kwargs):
"""Calculate the exponential of all elements."""
def exp2(x, **kwargs):
"""Calculate 2**x for all elements."""
def expm1(x, **kwargs):
"""Calculate exp(x) - 1 for all elements."""
def log(x, **kwargs):
"""Natural logarithm element-wise."""
def log2(x, **kwargs):
"""Base-2 logarithm of x."""
def log10(x, **kwargs):
"""Base-10 logarithm of x."""
def log1p(x, **kwargs):
"""Natural logarithm of 1 + x element-wise."""
def logaddexp(x1, x2, **kwargs):
"""Logarithm of sum of exponentials element-wise."""
def logaddexp2(x1, x2, **kwargs):
"""Logarithm base 2 of sum of exponentials."""
# Power and root functions
def sqrt(x, **kwargs):
"""Square root element-wise."""
def cbrt(x, **kwargs):
"""Cube root element-wise."""
def square(x, **kwargs):
"""Square of input element-wise."""
def reciprocal(x, **kwargs):
"""Reciprocal (1/x) element-wise."""
# Rounding functions
def around(x, decimals=0, **kwargs):
"""Round to given number of decimals."""
def round(x, decimals=0, **kwargs):
"""Round to given number of decimals (alias for around)."""
def rint(x, **kwargs):
"""Round to nearest integer."""
def fix(x, **kwargs):
"""Round to nearest integer towards zero."""
def floor(x, **kwargs):
"""Floor of input element-wise."""
def ceil(x, **kwargs):
"""Ceiling of input element-wise."""
def trunc(x, **kwargs):
"""Truncated value of input element-wise."""
# Floating point functions
def isfinite(x, **kwargs):
"""Test finiteness element-wise (not infinity or NaN)."""
def isinf(x, **kwargs):
"""Test for positive or negative infinity."""
def isnan(x, **kwargs):
"""Test for NaN element-wise."""
def isneginf(x, **kwargs):
"""Test for negative infinity element-wise."""
def isposinf(x, **kwargs):
"""Test for positive infinity element-wise."""
def signbit(x, **kwargs):
"""Test whether sign bit is set element-wise."""
def copysign(x1, x2, **kwargs):
"""Change sign of x1 to match sign of x2."""
def frexp(x, **kwargs):
"""Decompose into mantissa and exponent."""
def ldexp(x1, x2, **kwargs):
"""Compute x1 * 2**x2 element-wise."""
def nextafter(x1, x2, **kwargs):
"""Return next floating-point value after x1 towards x2."""
def spacing(x, **kwargs):
"""Return spacing between x and nearest adjacent number."""
# Complex number functions
def real(val):
"""Return real part of complex array."""
def imag(val):
"""Return imaginary part of complex array."""
def conj(x, **kwargs):
"""Return complex conjugate element-wise."""
def conjugate(x, **kwargs):
"""Return complex conjugate element-wise (alias for conj)."""
def angle(z, deg=False):
"""Return argument of complex number."""
# Bit manipulation (integer arrays)
def bitwise_and(x1, x2, **kwargs):
"""Compute bitwise AND element-wise."""
def bitwise_or(x1, x2, **kwargs):
"""Compute bitwise OR element-wise."""
def bitwise_xor(x1, x2, **kwargs):
"""Compute bitwise XOR element-wise."""
def bitwise_not(x, **kwargs):
"""Compute bitwise NOT element-wise."""
def invert(x, **kwargs):
"""Compute bitwise NOT element-wise (alias for bitwise_not)."""
def left_shift(x1, x2, **kwargs):
"""Shift bits to the left."""
def right_shift(x1, x2, **kwargs):
"""Shift bits to the right."""
# Logical operations
def logical_and(x1, x2, **kwargs):
"""Compute logical AND element-wise."""
def logical_or(x1, x2, **kwargs):
"""Compute logical OR element-wise."""
def logical_xor(x1, x2, **kwargs):
"""Compute logical XOR element-wise."""
def logical_not(x, **kwargs):
"""Compute logical NOT element-wise."""
# Basic linear algebra
def dot(a, b):
"""Dot product of two arrays."""
def matmul(x1, x2):
"""Matrix product of two arrays."""
def tensordot(a, b, axes=2):
"""Compute tensor dot product along specified axes."""
def outer(a, b):
"""Compute outer product of two vectors."""
def inner(a, b):
"""Inner product of two arrays."""
def vdot(a, b):
"""Return dot product of two vectors."""
def einsum(subscripts, *operands, **kwargs):
"""Evaluate Einstein summation convention."""
def kron(a, b):
"""Kronecker product of two arrays."""
# Miscellaneous operations
def clip(a, a_min, a_max, **kwargs):
"""Clip values to specified range."""
def fabs(x, **kwargs):
"""Compute absolute values element-wise."""
def sign(x, **kwargs):
"""Return element-wise indication of sign."""
def heaviside(x1, x2, **kwargs):
"""Compute Heaviside step function."""
def maximum(x1, x2, **kwargs):
"""Element-wise maximum of arrays."""
def minimum(x1, x2, **kwargs):
"""Element-wise minimum of arrays."""
def fmax(x1, x2, **kwargs):
"""Element-wise maximum, ignoring NaNs."""
def fmin(x1, x2, **kwargs):
"""Element-wise minimum, ignoring NaNs."""
def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
"""Replace NaN with zero and infinity with large numbers."""
def interp(x, xp, fp, left=None, right=None, period=None):
"""One-dimensional linear interpolation."""Aggregate operations that reduce array dimensions.
# Statistical reductions
def sum(a, axis=None, dtype=None, keepdims=False, split_every=None):
"""
Sum of array elements over given axes.
Parameters:
- a: Input array
- axis: Axis or axes along which to sum
- dtype: Data type for result
- keepdims: Keep reduced dimensions as size-one dimensions
- split_every: Branching factor for reduction tree
Returns:
dask.array.Array: Sum along specified axes
"""
def mean(a, axis=None, dtype=None, keepdims=False, split_every=None):
"""
Arithmetic mean along specified axes.
Parameters:
- a: Input array
- axis: Axis or axes along which to compute mean
- dtype: Data type for result
- keepdims: Keep reduced dimensions
- split_every: Branching factor for reduction tree
Returns:
dask.array.Array: Mean along specified axes
"""
def std(a, axis=None, dtype=None, keepdims=False, ddof=0, split_every=None):
"""
Standard deviation along specified axes.
Parameters:
- a: Input array
- axis: Axis or axes along which to compute standard deviation
- dtype: Data type for result
- keepdims: Keep reduced dimensions
- ddof: Delta degrees of freedom
- split_every: Branching factor for reduction tree
Returns:
dask.array.Array: Standard deviation
"""
def var(a, axis=None, dtype=None, keepdims=False, ddof=0, split_every=None):
"""
Variance along specified axes.
Parameters:
- a: Input array
- axis: Axis or axes along which to compute variance
- dtype: Data type for result
- keepdims: Keep reduced dimensions
- ddof: Delta degrees of freedom
- split_every: Branching factor for reduction tree
Returns:
dask.array.Array: Variance
"""
# Extrema
def min(a, axis=None, keepdims=False, split_every=None):
"""Minimum values along specified axes."""
def max(a, axis=None, keepdims=False, split_every=None):
"""Maximum values along specified axes."""
def argmin(a, axis=None, split_every=None):
"""Indices of minimum values along specified axis."""
def argmax(a, axis=None, split_every=None):
"""Indices of maximum values along specified axis."""
def amin(a, axis=None, keepdims=False, split_every=None):
"""Minimum values along specified axes (alias for min)."""
def amax(a, axis=None, keepdims=False, split_every=None):
"""Maximum values along specified axes (alias for max)."""
# Logical reductions
def all(a, axis=None, keepdims=False, split_every=None):
"""Test whether all array elements evaluate to True."""
def any(a, axis=None, keepdims=False, split_every=None):
"""Test whether any array element evaluates to True."""
# Other reductions
def prod(a, axis=None, dtype=None, keepdims=False, split_every=None):
"""Product of array elements over given axes."""
def product(a, axis=None, dtype=None, keepdims=False, split_every=None):
"""Product of array elements (alias for prod)."""
def cumsum(a, axis=None, dtype=None):
"""Cumulative sum along specified axis."""
def cumprod(a, axis=None, dtype=None):
"""Cumulative product along specified axis."""
def cumulative_sum(a, axis=None, dtype=None):
"""Cumulative sum (alias for cumsum)."""
def cumulative_prod(a, axis=None, dtype=None):
"""Cumulative product (alias for cumprod)."""
# NaN-aware reductions
def nansum(a, axis=None, dtype=None, keepdims=False, split_every=None):
"""Sum of array elements, treating NaNs as zero."""
def nanmean(a, axis=None, dtype=None, keepdims=False, split_every=None):
"""Mean of array elements, ignoring NaNs."""
def nanstd(a, axis=None, dtype=None, keepdims=False, ddof=0, split_every=None):
"""Standard deviation ignoring NaNs."""
def nanvar(a, axis=None, dtype=None, keepdims=False, ddof=0, split_every=None):
"""Variance ignoring NaNs."""
def nanmin(a, axis=None, keepdims=False, split_every=None):
"""Minimum values ignoring NaNs."""
def nanmax(a, axis=None, keepdims=False, split_every=None):
"""Maximum values ignoring NaNs."""
def nanprod(a, axis=None, dtype=None, keepdims=False, split_every=None):
"""Product of array elements, treating NaNs as one."""
def nanargmin(a, axis=None, split_every=None):
"""Indices of minimum values ignoring NaNs."""
def nanargmax(a, axis=None, split_every=None):
"""Indices of maximum values ignoring NaNs."""
def nancumsum(a, axis=None, dtype=None):
"""Cumulative sum ignoring NaNs."""
def nancumprod(a, axis=None, dtype=None):
"""Cumulative product ignoring NaNs."""
def nanmedian(a, axis=None, keepdims=False):
"""Median ignoring NaNs."""
def nanquantile(a, q, axis=None, keepdims=False, interpolation='linear'):
"""Quantiles ignoring NaNs."""
def nanpercentile(a, q, axis=None, keepdims=False, interpolation='linear'):
"""Percentiles ignoring NaNs."""
# Count and validation reductions
def count_nonzero(a, axis=None, keepdims=False, split_every=None):
"""Count non-zero elements along specified axes."""
def ptp(a, axis=None, keepdims=False):
"""Peak-to-peak (maximum - minimum) value."""
# Additional statistical functions
def median(a, axis=None, keepdims=False):
"""Median of array elements along specified axes."""
def quantile(a, q, axis=None, keepdims=False, interpolation='linear'):
"""Compute quantiles along specified axes."""
def percentile(a, q, axis=None, keepdims=False, interpolation='linear'):
"""Compute percentiles along specified axes."""
# Top-k operations
def topk(a, k, axis=None, split_every=None):
"""Find top k values along specified axis."""
def argtopk(a, k, axis=None, split_every=None):
"""Find indices of top k values along specified axis."""
# Moment and correlation functions
def moment(a, moment, axis=None, keepdims=False):
"""Calculate nth moment about the mean."""
def skew(a, axis=None, keepdims=False, bias=True):
"""Compute sample skewness of data."""
def kurtosis(a, axis=None, keepdims=False, fisher=True, bias=True):
"""Compute kurtosis (Fisher or Pearson) of dataset."""Functions for changing array shape and structure.
def reshape(a, shape, merge_chunks=True): ...
def transpose(a, axes=None): ...
def swapaxes(a, axis1, axis2): ...
def moveaxis(a, source, destination): ...
def squeeze(a, axis=None): ...
def expand_dims(a, axis): ...
def concatenate(seq, axis=0, allow_unknown_chunksizes=False): ...
def stack(arrays, axis=0, allow_unknown_chunksizes=False): ...
def block(arrays): ...
def split(ary, indices_or_sections, axis=0): ...
def hsplit(ary, indices_or_sections): ...
def vsplit(ary, indices_or_sections): ...
def flip(m, axis=None): ...
def fliplr(m): ...
def flipud(m): ...
def roll(a, shift, axis=None): ...
def rot90(m, k=1, axes=(0, 1)): ...
# Advanced array operations
def take(a, indices, axis=None): ...
def choose(a, choices, mode='raise'): ...
def compress(condition, a, axis=None): ...
def extract(condition, arr): ...
def place(arr, mask, vals): ...
def put(a, ind, v, mode='raise'): ...
def putmask(a, mask, values): ...
def select(condlist, choicelist, default=0): ...
def where(condition, x=None, y=None): ...
# Indexing and searching
def argwhere(a): ...
def nonzero(a): ...
def flatnonzero(a): ...
def searchsorted(a, v, side='left', sorter=None): ...
# Array testing
def allclose(a, b, rtol=1e-5, atol=1e-8, equal_nan=False): ...
def isclose(a, b, rtol=1e-5, atol=1e-8, equal_nan=False): ...
def isin(element, test_elements, assume_unique=False, invert=False): ...
# Histograms
def histogram(a, bins=10, range=None, weights=None, density=None): ...
def histogram2d(x, y, bins=10, range=None, weights=None, density=None): ...
def histogramdd(sample, bins=10, range=None, weights=None, density=None): ...
def bincount(x, weights=None, minlength=0): ...
def digitize(x, bins, right=False): ...
# Sorting and ordering
def sort(a, axis=-1, kind=None, order=None): ...
def argsort(a, axis=-1, kind=None, order=None): ...
def partition(a, kth, axis=-1, kind='introselect', order=None): ...
def argpartition(a, kth, axis=-1, kind='introselect', order=None): ...
# Set operations
def unique(ar, return_index=False, return_inverse=False, return_counts=False, axis=None): ...
def union1d(ar1, ar2): ...
def intersect1d(ar1, ar2, assume_unique=False, return_indices=False): ...
def setdiff1d(ar1, ar2, assume_unique=False): ...
def setxor1d(ar1, ar2, assume_unique=False): ...
def in1d(ar1, ar2, assume_unique=False, invert=False): ...
# Array padding and tiling
def pad(array, pad_width, mode='constant', **kwargs): ...
def tile(A, reps): ...
def repeat(a, repeats, axis=None): ...
# Matrix operations
def diag(v, k=0): ...
def diagonal(a, offset=0, axis1=0, axis2=1): ...
def trace(a, offset=0, axis1=0, axis2=1, dtype=None): ...
def tri(N, M=None, k=0, dtype=float): ...
def tril(m, k=0): ...
def triu(m, k=0): ...
def tril_indices(n, k=0, m=None): ...
def triu_indices(n, k=0, m=None): ...
def tril_indices_from(arr, k=0): ...
def triu_indices_from(arr, k=0): ...
# Multi-dimensional array indexing
def unravel_index(indices, shape, order='C'): ...
def ravel_multi_index(multi_index, dims, mode='raise', order='C'): ...
def ix_(*args): ...
def meshgrid(*xi, copy=True, sparse=False, indexing='xy'): ...
def mgrid(): ...
def ogrid(): ...
# Statistical functions
def average(a, axis=None, weights=None, returned=False): ...
def corrcoef(x, y=None, rowvar=True, bias=None, ddof=None): ...
def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None, aweights=None): ...
def percentile(a, q, axis=None, interpolation='linear', keepdims=False): ...
def quantile(a, q, axis=None, interpolation='linear', keepdims=False): ...
def nanpercentile(a, q, axis=None, interpolation='linear', keepdims=False): ...
def nanquantile(a, q, axis=None, interpolation='linear', keepdims=False): ...
# Array shape utilities
def atleast_1d(*arys): ...
def atleast_2d(*arys): ...
def atleast_3d(*arys): ...
def broadcast_arrays(*args, **kwargs): ...
def broadcast_to(array, shape, chunks=None): ...
def squeeze(a, axis=None): ...
def expand_dims(a, axis): ...Save and load arrays from various storage formats.
def store(sources, targets, lock=True, regions=None, compute=True,
return_stored=False, **kwargs):
"""
Store arrays to various backends.
Parameters:
- sources: Arrays to store
- targets: Storage targets
- lock: Use locks for thread safety
- regions: Storage regions
- compute: Whether to compute immediately
- return_stored: Return stored arrays
Returns:
None or stored arrays if return_stored=True
"""
def to_zarr(arr, url, component=None, storage_options=None,
overwrite=False, region=None, compute=True, return_stored=False,
**kwargs):
"""Save array to Zarr format."""
def from_zarr(url, component=None, storage_options=None, chunks=None,
**kwargs):
"""Load array from Zarr format."""
def to_hdf5(filename, datapath, array, **kwargs):
"""Save array to HDF5 format."""
def to_npy_stack(dirname, array, axis=0):
"""Save array as stack of .npy files."""
def from_npy_stack(dirname, mmap_mode='r'):
"""Load array from stack of .npy files."""Specialized array operations for complex computations.
def map_blocks(func, *arrays, dtype=None, chunks=None, drop_axis=None,
new_axis=None, **kwargs):
"""
Apply function to blocks of arrays.
Parameters:
- func: Function to apply to each block
- *arrays: Input arrays
- dtype: Output data type
- chunks: Output chunk specification
- drop_axis: Axes to remove from output
- new_axis: Axes to add to output
- **kwargs: Additional arguments to func
Returns:
dask.array.Array: Result of blockwise operation
"""
def blockwise(func, output_indices, *arrays_and_indices, **kwargs):
"""
General blockwise operation with Einstein notation.
Parameters:
- func: Function to apply
- output_indices: Output dimension labels
- *arrays_and_indices: Arrays and their dimension labels
- **kwargs: Additional parameters
Returns:
dask.array.Array: Result array
"""
def atop(func, output_indices, *arrays_and_indices, **kwargs):
"""Alias for blockwise."""
def apply_along_axis(func1d, axis, arr, *args, dtype=None, shape=None, **kwargs):
"""
Apply function to 1-D slices along given axis.
Parameters:
- func1d: Function to apply to 1-D slices
- axis: Axis along which to apply function
- arr: Input array
- *args: Additional arguments to func1d
- dtype: Output data type
- shape: Output shape per slice
- **kwargs: Additional keyword arguments
Returns:
dask.array.Array: Result of applying function along axis
"""
def apply_gufunc(func, signature, *args, axes=None, axis=None, keepdims=False,
output_dtypes=None, output_sizes=None, vectorize=None, **kwargs):
"""
Apply generalized universal function over trailing axes.
Parameters:
- func: Function to apply
- signature: Generalized ufunc signature
- *args: Input arrays
- axes: Axes over which to apply function
- axis: Single axis specification
- keepdims: Keep reduced dimensions
- output_dtypes: Output data types
- output_sizes: Output dimension sizes
- vectorize: Vectorize the function
- **kwargs: Additional arguments
Returns:
dask.array.Array: Result of gufunc application
"""Advanced linear algebra operations from dask.array.linalg.
# Basic linear algebra operations
def norm(x, ord=None, axis=None, keepdims=False):
"""
Compute vector or matrix norm.
Parameters:
- x: Input array
- ord: Order of the norm (None, 'fro', 'nuc', inf, -inf, int)
- axis: Axis along which to compute norm
- keepdims: Keep reduced dimensions
Returns:
dask.array.Array: Norm of the input
"""
def solve(a, b):
"""
Solve linear system ax = b.
Parameters:
- a: Coefficient matrix (square)
- b: Dependent variable values
Returns:
dask.array.Array: Solution to the system
"""
def inv(a):
"""
Compute matrix inverse.
Parameters:
- a: Input matrix
Returns:
dask.array.Array: Inverse matrix
"""
def pinv(a, rcond=1e-15):
"""
Compute Moore-Penrose pseudoinverse.
Parameters:
- a: Input matrix
- rcond: Cutoff for small singular values
Returns:
dask.array.Array: Pseudoinverse matrix
"""
def lstsq(a, b, rcond=None):
"""
Solve least-squares problem.
Parameters:
- a: Coefficient matrix
- b: Dependent variable values
- rcond: Cutoff ratio for small singular values
Returns:
tuple: (solution, residuals, rank, singular_values)
"""
# Matrix decompositions
def svd(a, full_matrices=True, compute_uv=True):
"""
Singular Value Decomposition.
Parameters:
- a: Input matrix
- full_matrices: Return full-sized U and Vh matrices
- compute_uv: Compute U and Vh in addition to s
Returns:
tuple: (U, s, Vh) if compute_uv else s
"""
def qr(a, mode='reduced'):
"""
QR decomposition.
Parameters:
- a: Input matrix
- mode: Decomposition mode ('reduced', 'complete', 'r', 'raw')
Returns:
tuple: (Q, R) or R depending on mode
"""
def lu(a):
"""
LU decomposition with partial pivoting.
Parameters:
- a: Input matrix
Returns:
tuple: (P, L, U) where P is permutation, L lower, U upper triangular
"""
def cholesky(a):
"""
Cholesky decomposition for positive definite matrices.
Parameters:
- a: Positive definite input matrix
Returns:
dask.array.Array: Lower triangular Cholesky factor
"""
def eig(a):
"""
Compute eigenvalues and eigenvectors.
Parameters:
- a: Input matrix
Returns:
tuple: (eigenvalues, eigenvectors)
"""
def eigh(a, UPLO='L'):
"""
Compute eigenvalues and eigenvectors of Hermitian matrix.
Parameters:
- a: Hermitian input matrix
- UPLO: Use upper ('U') or lower ('L') triangle
Returns:
tuple: (eigenvalues, eigenvectors)
"""
def eigvals(a):
"""
Compute eigenvalues only.
Parameters:
- a: Input matrix
Returns:
dask.array.Array: Eigenvalues
"""
def eigvalsh(a, UPLO='L'):
"""
Compute eigenvalues of Hermitian matrix.
Parameters:
- a: Hermitian input matrix
- UPLO: Use upper ('U') or lower ('L') triangle
Returns:
dask.array.Array: Eigenvalues
"""
# Matrix properties and operations
def det(a):
"""
Compute matrix determinant.
Parameters:
- a: Input matrix
Returns:
dask.array.Array: Determinant
"""
def slogdet(a):
"""
Compute sign and log of determinant.
Parameters:
- a: Input matrix
Returns:
tuple: (sign, logdet)
"""
def matrix_rank(M, tol=None, hermitian=False):
"""
Compute matrix rank using SVD.
Parameters:
- M: Input matrix
- tol: Threshold below which SVD values are zero
- hermitian: Whether M is Hermitian
Returns:
dask.array.Array: Matrix rank
"""
def cond(x, p=None):
"""
Compute condition number.
Parameters:
- x: Input matrix
- p: Order of the norm used in computation
Returns:
dask.array.Array: Condition number
"""
# Tensor operations
def multi_dot(arrays):
"""
Compute dot product of multiple arrays efficiently.
Parameters:
- arrays: Sequence of arrays to multiply
Returns:
dask.array.Array: Matrix product result
"""
def matrix_power(a, n):
"""
Raise matrix to integer power.
Parameters:
- a: Input matrix
- n: Integer exponent
Returns:
dask.array.Array: Matrix raised to power n
"""Fast Fourier Transform operations from dask.array.fft.
# 1-D FFT functions
def fft(a, n=None, axis=-1, norm=None):
"""
Compute 1-D discrete Fourier Transform.
Parameters:
- a: Input array
- n: Length of transformed axis (zero-padding/truncation)
- axis: Axis over which to compute FFT
- norm: Normalization mode ('backward', 'ortho', 'forward')
Returns:
dask.array.Array: Complex FFT result
"""
def ifft(a, n=None, axis=-1, norm=None):
"""
Compute 1-D inverse discrete Fourier Transform.
Parameters:
- a: Input array
- n: Length of transformed axis
- axis: Axis over which to compute inverse FFT
- norm: Normalization mode
Returns:
dask.array.Array: Complex inverse FFT result
"""
def rfft(a, n=None, axis=-1, norm=None):
"""
Compute 1-D FFT for real input.
Parameters:
- a: Input real array
- n: Length of transformed axis
- axis: Axis over which to compute FFT
- norm: Normalization mode
Returns:
dask.array.Array: Complex FFT result (half spectrum)
"""
def irfft(a, n=None, axis=-1, norm=None):
"""
Compute inverse of rfft.
Parameters:
- a: Input complex array
- n: Length of output axis
- axis: Axis over which to compute inverse FFT
- norm: Normalization mode
Returns:
dask.array.Array: Real inverse FFT result
"""
def hfft(a, n=None, axis=-1, norm=None):
"""
Compute FFT of signal with Hermitian symmetry.
Parameters:
- a: Input array with Hermitian symmetry
- n: Length of output axis
- axis: Axis over which to compute FFT
- norm: Normalization mode
Returns:
dask.array.Array: Real FFT result
"""
def ihfft(a, n=None, axis=-1, norm=None):
"""
Compute inverse FFT of real signal.
Parameters:
- a: Input real array
- n: Length of output axis
- axis: Axis over which to compute inverse FFT
- norm: Normalization mode
Returns:
dask.array.Array: Complex result with Hermitian symmetry
"""
# 2-D FFT functions
def fft2(a, s=None, axes=(-2, -1), norm=None):
"""
Compute 2-D discrete Fourier Transform.
Parameters:
- a: Input array
- s: Shape of output (zero-padding/truncation)
- axes: Axes over which to compute 2-D FFT
- norm: Normalization mode
Returns:
dask.array.Array: Complex 2-D FFT result
"""
def ifft2(a, s=None, axes=(-2, -1), norm=None):
"""
Compute 2-D inverse discrete Fourier Transform.
Parameters:
- a: Input array
- s: Shape of output
- axes: Axes over which to compute 2-D inverse FFT
- norm: Normalization mode
Returns:
dask.array.Array: Complex 2-D inverse FFT result
"""
def rfft2(a, s=None, axes=(-2, -1), norm=None):
"""
Compute 2-D FFT for real input.
Parameters:
- a: Input real array
- s: Shape of output
- axes: Axes over which to compute 2-D FFT
- norm: Normalization mode
Returns:
dask.array.Array: Complex 2-D FFT result
"""
def irfft2(a, s=None, axes=(-2, -1), norm=None):
"""
Compute 2-D inverse of rfft2.
Parameters:
- a: Input complex array
- s: Shape of output
- axes: Axes over which to compute 2-D inverse FFT
- norm: Normalization mode
Returns:
dask.array.Array: Real 2-D inverse FFT result
"""
# N-D FFT functions
def fftn(a, s=None, axes=None, norm=None):
"""
Compute N-D discrete Fourier Transform.
Parameters:
- a: Input array
- s: Shape of output along transformed axes
- axes: Axes over which to compute N-D FFT
- norm: Normalization mode
Returns:
dask.array.Array: Complex N-D FFT result
"""
def ifftn(a, s=None, axes=None, norm=None):
"""
Compute N-D inverse discrete Fourier Transform.
Parameters:
- a: Input array
- s: Shape of output along transformed axes
- axes: Axes over which to compute N-D inverse FFT
- norm: Normalization mode
Returns:
dask.array.Array: Complex N-D inverse FFT result
"""
def rfftn(a, s=None, axes=None, norm=None):
"""
Compute N-D FFT for real input.
Parameters:
- a: Input real array
- s: Shape of output along transformed axes
- axes: Axes over which to compute N-D FFT
- norm: Normalization mode
Returns:
dask.array.Array: Complex N-D FFT result
"""
def irfftn(a, s=None, axes=None, norm=None):
"""
Compute N-D inverse of rfftn.
Parameters:
- a: Input complex array
- s: Shape of output along transformed axes
- axes: Axes over which to compute N-D inverse FFT
- norm: Normalization mode
Returns:
dask.array.Array: Real N-D inverse FFT result
"""
# Helper functions
def fftfreq(n, d=1.0, chunks=None):
"""
Return discrete Fourier Transform sample frequencies.
Parameters:
- n: Window length
- d: Sample spacing
- chunks: Chunk specification for output
Returns:
dask.array.Array: Sample frequencies
"""
def rfftfreq(n, d=1.0, chunks=None):
"""
Return sample frequencies for rfft.
Parameters:
- n: Window length
- d: Sample spacing
- chunks: Chunk specification for output
Returns:
dask.array.Array: Sample frequencies for real FFT
"""
def fftshift(x, axes=None):
"""
Shift zero-frequency component to center.
Parameters:
- x: Input array
- axes: Axes over which to shift (None for all)
Returns:
dask.array.Array: Shifted array
"""
def ifftshift(x, axes=None):
"""
Inverse of fftshift.
Parameters:
- x: Input array
- axes: Axes over which to shift (None for all)
Returns:
dask.array.Array: Inverse shifted array
"""Random number generation from dask.array.random.
# Random state management
class Generator:
"""
Random number generator using the new numpy.random.Generator interface.
Parameters:
- bit_generator: Bit generator instance (PCG64, MT19937, etc.)
"""
def __init__(self, bit_generator):
"""Initialize Generator with bit generator."""
def random(self, size=None, chunks=None, **kwargs):
"""Generate random floats in [0, 1)."""
def integers(self, low, high=None, size=None, dtype=int,
endpoint=False, chunks=None, **kwargs):
"""Generate random integers."""
def normal(self, loc=0.0, scale=1.0, size=None, chunks=None, **kwargs):
"""Generate normally distributed random numbers."""
def uniform(self, low=0.0, high=1.0, size=None, chunks=None, **kwargs):
"""Generate uniformly distributed random numbers."""
class RandomState:
"""
Legacy random state interface compatible with numpy.random.RandomState.
Parameters:
- seed: Random seed for reproducibility
"""
def __init__(self, seed=None):
"""Initialize RandomState with optional seed."""
def random_sample(self, size=None, chunks=None, **kwargs):
"""Generate random floats in [0, 1)."""
def randint(self, low, high=None, size=None, dtype=int, chunks=None, **kwargs):
"""Generate random integers."""
def normal(self, loc=0.0, scale=1.0, size=None, chunks=None, **kwargs):
"""Generate normally distributed random numbers."""
def uniform(self, low=0.0, high=1.0, size=None, chunks=None, **kwargs):
"""Generate uniformly distributed random numbers."""
# Default random functions using global state
def random(size=None, chunks=None, **kwargs):
"""
Generate random floats in [0, 1).
Parameters:
- size: Output shape
- chunks: Chunk specification
- **kwargs: Additional arguments
Returns:
dask.array.Array: Random float array
"""
def randint(low, high=None, size=None, dtype=int, chunks=None, **kwargs):
"""
Generate random integers.
Parameters:
- low: Lowest integer (inclusive) or highest if high is None
- high: Highest integer (exclusive)
- size: Output shape
- dtype: Integer type
- chunks: Chunk specification
Returns:
dask.array.Array: Random integer array
"""
# Continuous distributions
def beta(a, b, size=None, chunks=None, **kwargs):
"""Generate beta distributed random numbers."""
def binomial(n, p, size=None, chunks=None, **kwargs):
"""Generate binomial distributed random numbers."""
def chisquare(df, size=None, chunks=None, **kwargs):
"""Generate chi-square distributed random numbers."""
def dirichlet(alpha, size=None, chunks=None, **kwargs):
"""Generate Dirichlet distributed random numbers."""
def exponential(scale=1.0, size=None, chunks=None, **kwargs):
"""
Generate exponentially distributed random numbers.
Parameters:
- scale: Scale parameter (1/rate)
- size: Output shape
- chunks: Chunk specification
Returns:
dask.array.Array: Exponentially distributed random numbers
"""
def f(dfnum, dfden, size=None, chunks=None, **kwargs):
"""Generate F-distributed random numbers."""
def gamma(shape, scale=1.0, size=None, chunks=None, **kwargs):
"""
Generate gamma distributed random numbers.
Parameters:
- shape: Shape parameter
- scale: Scale parameter
- size: Output shape
- chunks: Chunk specification
Returns:
dask.array.Array: Gamma distributed random numbers
"""
def geometric(p, size=None, chunks=None, **kwargs):
"""Generate geometric distributed random numbers."""
def gumbel(loc=0.0, scale=1.0, size=None, chunks=None, **kwargs):
"""Generate Gumbel distributed random numbers."""
def hypergeometric(ngood, nbad, nsample, size=None, chunks=None, **kwargs):
"""Generate hypergeometric distributed random numbers."""
def laplace(loc=0.0, scale=1.0, size=None, chunks=None, **kwargs):
"""Generate Laplace distributed random numbers."""
def logistic(loc=0.0, scale=1.0, size=None, chunks=None, **kwargs):
"""Generate logistic distributed random numbers."""
def lognormal(mean=0.0, sigma=1.0, size=None, chunks=None, **kwargs):
"""
Generate log-normal distributed random numbers.
Parameters:
- mean: Mean of underlying normal distribution
- sigma: Standard deviation of underlying normal distribution
- size: Output shape
- chunks: Chunk specification
Returns:
dask.array.Array: Log-normally distributed random numbers
"""
def logseries(p, size=None, chunks=None, **kwargs):
"""Generate log-series distributed random numbers."""
def multinomial(n, pvals, size=None, chunks=None, **kwargs):
"""Generate multinomial distributed random numbers."""
def multivariate_normal(mean, cov, size=None, chunks=None, **kwargs):
"""
Generate multivariate normal distributed random numbers.
Parameters:
- mean: Mean vector
- cov: Covariance matrix
- size: Number of samples
- chunks: Chunk specification
Returns:
dask.array.Array: Multivariate normal distributed samples
"""
def negative_binomial(n, p, size=None, chunks=None, **kwargs):
"""Generate negative binomial distributed random numbers."""
def noncentral_chisquare(df, nonc, size=None, chunks=None, **kwargs):
"""Generate non-central chi-square distributed random numbers."""
def noncentral_f(dfnum, dfden, nonc, size=None, chunks=None, **kwargs):
"""Generate non-central F distributed random numbers."""
def normal(loc=0.0, scale=1.0, size=None, chunks=None, **kwargs):
"""
Generate normal distributed random numbers.
Parameters:
- loc: Mean (location parameter)
- scale: Standard deviation (scale parameter)
- size: Output shape
- chunks: Chunk specification
Returns:
dask.array.Array: Normally distributed random numbers
"""
def pareto(a, size=None, chunks=None, **kwargs):
"""Generate Pareto distributed random numbers."""
def poisson(lam=1.0, size=None, chunks=None, **kwargs):
"""
Generate Poisson distributed random numbers.
Parameters:
- lam: Expected number of events (rate parameter)
- size: Output shape
- chunks: Chunk specification
Returns:
dask.array.Array: Poisson distributed random numbers
"""
def power(a, size=None, chunks=None, **kwargs):
"""Generate power distributed random numbers."""
def rayleigh(scale=1.0, size=None, chunks=None, **kwargs):
"""Generate Rayleigh distributed random numbers."""
def standard_cauchy(size=None, chunks=None, **kwargs):
"""Generate standard Cauchy distributed random numbers."""
def standard_exponential(size=None, chunks=None, **kwargs):
"""Generate standard exponential distributed random numbers."""
def standard_gamma(shape, size=None, chunks=None, **kwargs):
"""Generate standard gamma distributed random numbers."""
def standard_normal(size=None, chunks=None, **kwargs):
"""
Generate standard normal distributed random numbers.
Parameters:
- size: Output shape
- chunks: Chunk specification
Returns:
dask.array.Array: Standard normal distributed random numbers
"""
def standard_t(df, size=None, chunks=None, **kwargs):
"""Generate Student's t distributed random numbers."""
def triangular(left, mode, right, size=None, chunks=None, **kwargs):
"""Generate triangular distributed random numbers."""
def uniform(low=0.0, high=1.0, size=None, chunks=None, **kwargs):
"""
Generate uniform distributed random numbers.
Parameters:
- low: Lower bound (inclusive)
- high: Upper bound (exclusive)
- size: Output shape
- chunks: Chunk specification
Returns:
dask.array.Array: Uniformly distributed random numbers
"""
def vonmises(mu, kappa, size=None, chunks=None, **kwargs):
"""Generate von Mises distributed random numbers."""
def wald(mean, scale, size=None, chunks=None, **kwargs):
"""Generate Wald (inverse Gaussian) distributed random numbers."""
def weibull(a, size=None, chunks=None, **kwargs):
"""Generate Weibull distributed random numbers."""
def zipf(a, size=None, chunks=None, **kwargs):
"""Generate Zipf distributed random numbers."""
# Utility functions
def choice(a, size=None, replace=True, p=None, chunks=None, **kwargs):
"""
Generate random samples from array elements.
Parameters:
- a: Array to sample from or integer for arange(a)
- size: Output shape
- replace: Sample with replacement
- p: Probabilities for each element
- chunks: Chunk specification
Returns:
dask.array.Array: Random samples
"""
def permutation(x, chunks=None, **kwargs):
"""
Randomly permute sequence or array.
Parameters:
- x: Sequence to permute or integer for arange(x)
- chunks: Chunk specification
Returns:
dask.array.Array: Permuted array
"""
def shuffle(x, chunks=None, **kwargs):
"""
Shuffle array in-place along first axis.
Parameters:
- x: Array to shuffle
- chunks: Chunk specification for output
Returns:
dask.array.Array: Shuffled array
"""
def seed(seed=None):
"""
Seed the global random state.
Parameters:
- seed: Random seed for reproducibility
"""
def get_state():
"""Get current random state."""
def set_state(state):
"""Set random state."""import dask.array as da
import numpy as np
# Create from NumPy array
x_np = np.random.random((10000, 10000))
x_da = da.from_array(x_np, chunks=(1000, 1000))
# Create directly
y = da.random.random((10000, 10000), chunks=(1000, 1000))
z = da.zeros((5000, 5000), chunks=(1000, 1000))
# Basic operations maintain chunking
result = (x_da + y).sum(axis=0)import dask.array as da
# Different chunking approaches
x = da.random.random((10000, 10000), chunks='100MB') # Size-based
y = da.random.random((10000, 10000), chunks=(1000, 1000)) # Shape-based
z = da.random.random((10000, 10000), chunks='auto') # Automatic
# Rechunking for different access patterns
x_rechunked = x.rechunk((5000, 2000)) # Better for column operationsimport dask.array as da
# Linear algebra
A = da.random.random((5000, 3000), chunks=(1000, 1000))
B = da.random.random((3000, 2000), chunks=(1000, 1000))
C = da.dot(A, B) # Matrix multiplication
# Element-wise operations
x = da.linspace(0, 10, 100000, chunks=10000)
y = da.sin(x) * da.exp(-x/5)
# Reductions with custom chunking
large_sum = da.sum(y, split_every=8) # Control reduction treeimport dask.array as da
import numpy as np
def custom_filter(block):
"""Apply custom filtering to each block."""
return np.where(block > 0.5, block, 0)
# Apply to all blocks
x = da.random.random((10000, 10000), chunks=(1000, 1000))
filtered = da.map_blocks(custom_filter, x, dtype=x.dtype)
# More complex block operation
def normalize_block(block, axis=None):
"""Normalize each block independently."""
return (block - block.mean(axis=axis, keepdims=True)) / block.std(axis=axis, keepdims=True)
normalized = da.map_blocks(normalize_block, x, axis=1, dtype=x.dtype)Install with Tessl CLI
npx tessl i tessl/pypi-dask