ulab.numpy – Numerical approximation methods
- ulab.numpy.interp(x: ndarray, xp: ndarray, fp: ndarray, *, left: _float | None = None, right: _float | None = None) ndarray
- Parameters:
x (ulab.numpy.ndarray) – The x-coordinates at which to evaluate the interpolated values.
xp (ulab.numpy.ndarray) – The x-coordinates of the data points, must be increasing
fp (ulab.numpy.ndarray) – The y-coordinates of the data points, same length as xp
left – Value to return for
x < xp[0], default isfp[0].right – Value to return for
x > xp[-1], default isfp[-1].
Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x.
- ulab.numpy.trapz(y: ndarray, x: ndarray | None = None, dx: _float = 1.0) _float
- Parameters:
y (1D ulab.numpy.ndarray) – the values of the dependent variable
x (1D ulab.numpy.ndarray) – optional, the coordinates of the independent variable. Defaults to uniformly spaced values.
dx (float) – the spacing between sample points, if x=None
Returns the integral of y(x) using the trapezoidal rule.
- ulab.numpy.clip(a: _ScalarOrArrayLike, a_min: _ScalarOrArrayLike, a_max: _ScalarOrArrayLike) _ScalarOrNdArray
Clips (limits) the values in an array.
- Parameters:
a – Scalar or array containing elements to clip.
a_min – Minimum value, it will be broadcast against
a.a_max – Maximum value, it will be broadcast against
a.
- Returns:
A scalar or array with the elements of
a, but where values <a_minare replaced witha_min, and those >a_maxwitha_max.
- ulab.numpy.equal(x: _ScalarOrArrayLike, y: _ScalarOrArrayLike) _ScalarOrNdArray
Returns
x == yelement-wise.- Parameters:
y (x,) – Input scalar or array. If
x.shape != y.shapethey must be broadcastable to a common shape (which becomes the shape of the output.)- Returns:
A boolean scalar or array with the element-wise result of
x == y.
- ulab.numpy.not_equal(x: _ScalarOrArrayLike, y: _ScalarOrArrayLike) _bool | ndarray
Returns
x != yelement-wise.- Parameters:
y (x,) – Input scalar or array. If
x.shape != y.shapethey must be broadcastable to a common shape (which becomes the shape of the output.)- Returns:
A boolean scalar or array with the element-wise result of
x != y.
- ulab.numpy.isfinite(x: _ScalarOrNdArray) _bool | ndarray
Tests element-wise for finiteness (i.e., it should not be infinity or a NaN).
- Parameters:
x – Input scalar or ndarray.
- Returns:
A boolean scalar or array with True where
xis finite, and False otherwise.
- ulab.numpy.isinf(x: _ScalarOrNdArray) _bool | ndarray
Tests element-wise for positive or negative infinity.
- Parameters:
x – Input scalar or ndarray.
- Returns:
A boolean scalar or array with True where
xis positive or negative infinity, and False otherwise.
- ulab.numpy.maximum(x1: _ScalarOrArrayLike, x2: _ScalarOrArrayLike) _ScalarOrNdArray
Returns the element-wise maximum.
- Parameters:
x2 (x1,) – Input scalar or array. If
x.shape != y.shapethey must be broadcastable to a common shape (which becomes the shape of the output.)- Returns:
A scalar or array with the element-wise maximum of
x1andx2.
- ulab.numpy.minimum(x1: _ScalarOrArrayLike, x2: _ScalarOrArrayLike) _ScalarOrNdArray
Returns the element-wise minimum.
- Parameters:
x2 (x1,) – Input scalar or array. If
x.shape != y.shapethey must be broadcastable to a common shape (which becomes the shape of the output.)- Returns:
A scalar or array with the element-wise minimum of
x1andx2.
- ulab.numpy.nonzero(x: _ScalarOrArrayLike) ndarray
Returns the indices of elements that are non-zero.
- Parameters:
x – Input scalar or array. If
xis a scalar, it is treated as a single-element 1-d array.- Returns:
An array of indices that are non-zero.
- ulab.numpy.where(condition: _ScalarOrArrayLike, x: _ScalarOrArrayLike, y: _ScalarOrArrayLike) ndarray
Returns elements from
xorydepending oncondition.- Parameters:
condition – Input scalar or array. If an element (or scalar) is truthy, the corresponding element from
xis chosen, otherwiseyis used.condition,xandymust also be broadcastable to the same shape (which becomes the output shape.)y (x,) – Input scalar or array.
- Returns:
An array with elements from
xwhenconditionis truthy, andyelsewhere.
- ulab.numpy.arange(stop: _float, step: _float = 1, *, dtype: _DType = ulab.numpy.float) ndarray
- ulab.numpy.arange(start: _float, stop: _float, step: _float = 1, *, dtype: _DType = ulab.numpy.float) ndarray
Return a new 1-D array with elements ranging from
starttostop, with step sizestep.
- ulab.numpy.concatenate(arrays: Tuple[ndarray], *, axis: int = 0) ndarray
Join a sequence of arrays along an existing axis.
- ulab.numpy.empty(shape: int | Tuple[int, Ellipsis], *, dtype: _DType = ulab.numpy.float) ndarray
Return a new array of the given shape with all elements set to 0. An alias for numpy.zeros.
- ulab.numpy.eye(size: int, *, M: int | None = None, k: int = 0, dtype: _DType = ulab.numpy.float) ndarray
Return a new square array of size, with the diagonal elements set to 1 and the other elements set to 0. If k is given, the diagonal is shifted by the specified amount.
- ulab.numpy.full(shape: int | Tuple[int, Ellipsis], fill_value: _float | _bool, *, dtype: _DType = ulab.numpy.float) ndarray
Return a new array of the given shape with all elements set to 0.
- ulab.numpy.linspace(start: _float, stop: _float, *, dtype: _DType = ulab.numpy.float, num: int = 50, endpoint: _bool = True, retstep: _bool = False) ndarray
Return a new 1-D array with
numelements ranging fromstarttostoplinearly.
- ulab.numpy.logspace(start: _float, stop: _float, *, dtype: _DType = ulab.numpy.float, num: int = 50, endpoint: _bool = True, base: _float = 10.0) ndarray
Return a new 1-D array with
numevenly spaced elements on a log scale. The sequence starts atbase ** start, and ends withbase ** stop.
- ulab.numpy.ones(shape: int | Tuple[int, Ellipsis], *, dtype: _DType = ulab.numpy.float) ndarray
Return a new array of the given shape with all elements set to 1.
- ulab.numpy.zeros(shape: int | Tuple[int, Ellipsis], *, dtype: _DType = ulab.numpy.float) ndarray
Return a new array of the given shape with all elements set to 0.
- ulab.numpy._ArrayLike
- ulab.numpy._ScalarOrArrayLike
- ulab.numpy._ScalarOrNdArray
- ulab.numpy._DType
ulab.numpy.int8,ulab.numpy.uint8,ulab.numpy.int16,ulab.numpy.uint16,ulab.numpy.floatorulab.numpy.bool
- ulab.numpy.int8: _DType
Type code for signed integers in the range -128 .. 127 inclusive, like the ‘b’ typecode of
array.array
- ulab.numpy.int16: _DType
Type code for signed integers in the range -32768 .. 32767 inclusive, like the ‘h’ typecode of
array.array
- ulab.numpy.float: _DType
Type code for floating point values, like the ‘f’ typecode of
array.array
- ulab.numpy.uint8: _DType
Type code for unsigned integers in the range 0 .. 255 inclusive, like the ‘H’ typecode of
array.array
- ulab.numpy.uint16: _DType
Type code for unsigned integers in the range 0 .. 65535 inclusive, like the ‘h’ typecode of
array.array
- ulab.numpy.argmax(array: _ArrayLike, *, axis: int | None = None) int
Return the index of the maximum element of the 1D array
- ulab.numpy.argmin(array: _ArrayLike, *, axis: int | None = None) int
Return the index of the minimum element of the 1D array
- ulab.numpy.argsort(array: ndarray, *, axis: int = -1) ndarray
Returns an array which gives indices into the input array from least to greatest.
- ulab.numpy.cross(a: ndarray, b: ndarray) ndarray
Return the cross product of two vectors of length 3
- ulab.numpy.diff(array: ndarray, *, n: int = 1, axis: int = -1) ndarray
Return the numerical derivative of successive elements of the array, as an array. axis=None is not supported.
- ulab.numpy.flip(array: ndarray, *, axis: int | None = None) ndarray
Returns a new array that reverses the order of the elements along the given axis, or along all axes if axis is None.
- ulab.numpy.max(array: _ArrayLike, *, axis: int | None = None) float
Return the maximum element of the 1D array
- ulab.numpy.mean(array: _ArrayLike, *, axis: int | None = None) float
Return the mean element of the 1D array, as a number if axis is None, otherwise as an array.
- ulab.numpy.median(array: ndarray, *, axis: int = -1) ndarray
Find the median value in an array along the given axis, or along all axes if axis is None.
- ulab.numpy.min(array: _ArrayLike, *, axis: int | None = None) float
Return the minimum element of the 1D array
- ulab.numpy.roll(array: ndarray, distance: int, *, axis: int | None = None) None
Shift the content of a vector by the positions given as the second argument. If the
axiskeyword is supplied, the shift is applied to the given axis. The array is modified in place.
- ulab.numpy.sort(array: ndarray, *, axis: int = -1) ndarray
Sort the array along the given axis, or along all axes if axis is None. The array is modified in place.
- ulab.numpy.std(array: _ArrayLike, *, axis: int | None = None, ddof: int = 0) float
Return the standard deviation of the array, as a number if axis is None, otherwise as an array.
- ulab.numpy.sum(array: _ArrayLike, *, axis: int | None = None) float | int | ndarray
Return the sum of the array, as a number if axis is None, otherwise as an array.
- class ulab.numpy.ndarray
- ulab.numpy.set_printoptions(threshold: int | None = None, edgeitems: int | None = None) None
Set printing options
- ulab.numpy.array(values: ndarray | Iterable[float | bool | Iterable[Any]], *, dtype: _DType = ulab.numpy.float) ndarray
alternate constructor function for
ulab.numpy.ndarray. Mirrors numpy.array
- ulab.numpy.trace(m: ndarray) float
- Parameters:
m – a square matrix
Compute the trace of the matrix, the sum of its diagonal elements.
- ulab.numpy.dot(m1: ndarray, m2: ndarray) ndarray | float
-
Computes the product of two matrices, or two vectors. In the letter case, the inner product is returned.
- ulab.numpy.acos(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the inverse cosine function
- ulab.numpy.acosh(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the inverse hyperbolic cosine function
- ulab.numpy.asin(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the inverse sine function
- ulab.numpy.asinh(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the inverse hyperbolic sine function
- ulab.numpy.around(a: ndarray, *, decimals: int = 0) ndarray
Returns a new float array in which each element is rounded to
decimalsplaces.
- ulab.numpy.atan(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the inverse tangent function; the return values are in the range [-pi/2,pi/2].
- ulab.numpy.atanh(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the inverse hyperbolic tangent function
- ulab.numpy.arctan2(ya: _ScalarOrArrayLike, xa: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the inverse tangent function of y/x; the return values are in the range [-pi, pi].
- ulab.numpy.ceil(a: _ScalarOrArrayLike) _ScalarOrNdArray
Rounds numbers up to the next whole number
- ulab.numpy.cos(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the cosine function
- ulab.numpy.cosh(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the hyperbolic cosine function
- ulab.numpy.degrees(a: _ScalarOrArrayLike) _ScalarOrNdArray
Converts angles from radians to degrees
- ulab.numpy.erf(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the error function, which has applications in statistics
- ulab.numpy.erfc(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the complementary error function, which has applications in statistics
- ulab.numpy.exp(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the exponent function.
- ulab.numpy.expm1(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes $e^x-1$. In certain applications, using this function preserves numeric accuracy better than the
expfunction.
- ulab.numpy.floor(a: _ScalarOrArrayLike) _ScalarOrNdArray
Rounds numbers up to the next whole number
- ulab.numpy.gamma(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the gamma function
- ulab.numpy.lgamma(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the natural log of the gamma function
- ulab.numpy.log(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the natural log
- ulab.numpy.log10(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the log base 10
- ulab.numpy.log2(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the log base 2
- ulab.numpy.radians(a: _ScalarOrArrayLike) _ScalarOrNdArray
Converts angles from degrees to radians
- ulab.numpy.sin(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the sine function
- ulab.numpy.sinc(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the normalized sinc function
- ulab.numpy.sinh(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the hyperbolic sine
- ulab.numpy.sqrt(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the square root
- ulab.numpy.tan(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the tangent
- ulab.numpy.tanh(a: _ScalarOrArrayLike) _ScalarOrNdArray
Computes the hyperbolic tangent
- ulab.numpy.vectorize(f: Callable[[int], float] | Callable[[float], float], *, otypes: _DType | None = None) Callable[[_ScalarOrArrayLike], ndarray]
- Parameters:
f (callable) – The function to wrap
otypes – List of array types that may be returned by the function. None is interpreted to mean the return value is float.
Wrap a Python function
fso that it can be applied to arrays or scalars. A scalar passed to the wrapped function is treated as a single-element 1-D array. The callable must return only values of the types specified byotypes, or the result is undefined.