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 is fp[0].

  • 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: 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.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 start to stop, with step size step.

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

Join a sequence of arrays along an existing axis.

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

Return specified diagonals.

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 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) ndarray

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) 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._DType

ulab.numpy.int8, ulab.numpy.uint8, ulab.numpy.int16, ulab.numpy.uint16, ulab.numpy.float or ulab.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.bool: _DType

Type code for boolean values

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 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) 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.get_printoptions() Dict[str, int]

Get printing options

ulab.numpy.set_printoptions(threshold: int | None = None, edgeitems: int | None = 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) 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
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) ndarray

Computes the inverse cosine function

ulab.numpy.acosh(a: _ArrayLike) ndarray

Computes the inverse hyperbolic cosine function

ulab.numpy.asin(a: _ArrayLike) ndarray

Computes the inverse sine function

ulab.numpy.asinh(a: _ArrayLike) ndarray

Computes the inverse hyperbolic sine function

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

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

ulab.numpy.atan(a: _ArrayLike) ndarray

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

ulab.numpy.atanh(a: _ArrayLike) ndarray

Computes the inverse hyperbolic tangent function

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

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

ulab.numpy.ceil(a: _ArrayLike) ndarray

Rounds numbers up to the next whole number

ulab.numpy.cos(a: _ArrayLike) ndarray

Computes the cosine function

ulab.numpy.cosh(a: _ArrayLike) ndarray

Computes the hyperbolic cosine function

ulab.numpy.degrees(a: _ArrayLike) ndarray

Converts angles from radians to degrees

ulab.numpy.erf(a: _ArrayLike) ndarray

Computes the error function, which has applications in statistics

ulab.numpy.erfc(a: _ArrayLike) ndarray

Computes the complementary error function, which has applications in statistics

ulab.numpy.exp(a: _ArrayLike) ndarray

Computes the exponent function.

ulab.numpy.expm1(a: _ArrayLike) ndarray

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

ulab.numpy.floor(a: _ArrayLike) ndarray

Rounds numbers up to the next whole number

ulab.numpy.gamma(a: _ArrayLike) ndarray

Computes the gamma function

ulab.numpy.lgamma(a: _ArrayLike) ndarray

Computes the natural log of the gamma function

ulab.numpy.log(a: _ArrayLike) ndarray

Computes the natural log

ulab.numpy.log10(a: _ArrayLike) ndarray

Computes the log base 10

ulab.numpy.log2(a: _ArrayLike) ndarray

Computes the log base 2

ulab.numpy.radians(a: _ArrayLike) ndarray

Converts angles from degrees to radians

ulab.numpy.sin(a: _ArrayLike) ndarray

Computes the sine function

ulab.numpy.sinc(a: _ArrayLike) ndarray

Computes the normalized sinc function

ulab.numpy.sinh(a: _ArrayLike) ndarray

Computes the hyperbolic sine

ulab.numpy.sqrt(a: _ArrayLike) ndarray

Computes the square root

ulab.numpy.tan(a: _ArrayLike) ndarray

Computes the tangent

ulab.numpy.tanh(a: _ArrayLike) ndarray

Computes the hyperbolic tangent

ulab.numpy.vectorize(f: Callable[[int], float] | Callable[[float], float], *, otypes: _DType | None = 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.