# `ulab.numpy` – Numerical approximation methods

ulab.numpy.interp(x: ndarray, xp: ndarray, fp: ndarray, *, left: _float | None = None, right: _float | None = None)
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`, default is `fp`.

• right – Value to return for `x > xp[-1]`, default is `fp[-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: = 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.arange(stop: _float, step: _float = 1, *, dtype: _DType = ulab.numpy.float)
ulab.numpy.arange(start: _float, stop: _float, step: _float = 1, *, dtype: _DType = ulab.numpy.float)

Return a new 1-D array with elements ranging from `start` to `stop`, with step size `step`.

ulab.numpy.concatenate(arrays: Tuple[ndarray], *, axis: int = 0)

Join a sequence of arrays along an existing axis.

ulab.numpy.diag(a: ndarray, *, k: int = 0)

Return specified diagonals.

ulab.numpy.empty(shape: int | Tuple[int, Ellipsis], *, dtype: _DType = ulab.numpy.float)

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: = None, k: int = 0, dtype: _DType = ulab.numpy.float)

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)

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)

Return a new 1-D array with `num` elements ranging from `start` to `stop` linearly.

ulab.numpy.logspace(start: _float, stop: _float, *, dtype: _DType = ulab.numpy.float, num: int = 50, endpoint: _bool = True, base: _float = 10.0)

Return a new 1-D array with `num` evenly spaced elements on a log scale. The sequence starts at `base ** start`, and ends with `base ** stop`.

ulab.numpy.ones(shape: int | Tuple[int, Ellipsis], *, dtype: _DType = ulab.numpy.float)

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)

Return a new array of the given shape with all elements set to 0.

ulab.numpy._ArrayLike
ulab.numpy._DType
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.bool: _DType

Type code for boolean values

ulab.numpy.argmax(array: _ArrayLike, *, axis: = None) int

Return the index of the maximum element of the 1D array

ulab.numpy.argmin(array: _ArrayLike, *, axis: = None) int

Return the index of the minimum element of the 1D array

ulab.numpy.argsort(array: ndarray, *, axis: int = -1)

Returns an array which gives indices into the input array from least to greatest.

ulab.numpy.cross(a: ndarray, b: ndarray)

Return the cross product of two vectors of length 3

ulab.numpy.diff(array: ndarray, *, n: int = 1, axis: int = -1)

Return the numerical derivative of successive elements of the array, as an array. axis=None is not supported.

ulab.numpy.flip(array: ndarray, *, axis: = None)

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: = None)

Return the maximum element of the 1D array

ulab.numpy.mean(array: _ArrayLike, *, axis: = None)

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)

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: = None)

Return the minimum element of the 1D array

ulab.numpy.roll(array: ndarray, distance: int, *, axis: = None) None

Shift the content of a vector by the positions given as the second argument. If the `axis` keyword is supplied, the shift is applied to the given axis. The array is modified in place.

ulab.numpy.sort(array: ndarray, *, axis: int = -1)

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: = None, ddof: int = 0)

Return the standard deviation of the array, as a number if axis is None, otherwise as an array.

ulab.numpy.sum(array: _ArrayLike, *, axis: = None)

Return the sum of the array, as a number if axis is None, otherwise as an array.

class ulab.numpy.ndarray
ulab.numpy.get_printoptions() Dict[str, int]

Get printing options

ulab.numpy.set_printoptions(threshold: = None, edgeitems: = None) None

Set printing options

ulab.numpy.ndinfo(array: ndarray) None
ulab.numpy.array(values: ndarray | Iterable[float | bool | Iterable[Any]], *, dtype: _DType = ulab.numpy.float)

alternate constructor function for `ulab.numpy.ndarray`. Mirrors numpy.array

ulab.numpy.trace(m: ndarray)
Parameters:

m – a square matrix

Compute the trace of the matrix, the sum of its diagonal elements.

ulab.numpy.dot(m1: ndarray, m2: ndarray)
Parameters:
• m1 (ndarray) – a matrix, or a vector

• m2 (ndarray) – a matrix, or a vector

Computes the product of two matrices, or two vectors. In the letter case, the inner product is returned.

ulab.numpy.acos(a: _ArrayLike)

Computes the inverse cosine function

ulab.numpy.acosh(a: _ArrayLike)

Computes the inverse hyperbolic cosine function

ulab.numpy.asin(a: _ArrayLike)

Computes the inverse sine function

ulab.numpy.asinh(a: _ArrayLike)

Computes the inverse hyperbolic sine function

ulab.numpy.around(a: _ArrayLike, *, decimals: int = 0)

Returns a new float array in which each element is rounded to `decimals` places.

ulab.numpy.atan(a: _ArrayLike)

Computes the inverse tangent function; the return values are in the range [-pi/2,pi/2].

ulab.numpy.arctan2(ya: _ArrayLike, xa: _ArrayLike)

Computes the inverse tangent function of y/x; the return values are in the range [-pi, pi].

ulab.numpy.atanh(a: _ArrayLike)

Computes the inverse hyperbolic tangent function

ulab.numpy.ceil(a: _ArrayLike)

Rounds numbers up to the next whole number

ulab.numpy.cos(a: _ArrayLike)

Computes the cosine function

ulab.numpy.cosh(a: _ArrayLike)

Computes the hyperbolic cosine function

ulab.numpy.degrees(a: _ArrayLike)

Converts angles from radians to degrees

ulab.numpy.erf(a: _ArrayLike)

Computes the error function, which has applications in statistics

ulab.numpy.erfc(a: _ArrayLike)

Computes the complementary error function, which has applications in statistics

ulab.numpy.exp(a: _ArrayLike)

Computes the exponent function.

ulab.numpy.expm1(a: _ArrayLike)

Computes \$e^x-1\$. In certain applications, using this function preserves numeric accuracy better than the `exp` function.

ulab.numpy.floor(a: _ArrayLike)

Rounds numbers up to the next whole number

ulab.numpy.gamma(a: _ArrayLike)

Computes the gamma function

ulab.numpy.lgamma(a: _ArrayLike)

Computes the natural log of the gamma function

ulab.numpy.log(a: _ArrayLike)

Computes the natural log

ulab.numpy.log10(a: _ArrayLike)

Computes the log base 10

ulab.numpy.log2(a: _ArrayLike)

Computes the log base 2

Converts angles from degrees to radians

ulab.numpy.sin(a: _ArrayLike)

Computes the sine function

ulab.numpy.sinc(a: _ArrayLike)

Computes the normalized sinc function

ulab.numpy.sinh(a: _ArrayLike)

Computes the hyperbolic sine

ulab.numpy.sqrt(a: _ArrayLike)

Computes the square root

ulab.numpy.tan(a: _ArrayLike)

Computes the tangent

ulab.numpy.tanh(a: _ArrayLike)

Computes the hyperbolic tangent

ulab.numpy.vectorize(f: Callable[[int], float] | Callable[[float], float], *, otypes: = None) Callable[[_ArrayLike], 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 `f` so that it can be applied to arrays. The callable must return only values of the types specified by `otypes`, or the result is undefined.