Math#
This module provides NumPy-like math functions.
Modules:
|
Calculate the absolute value element-wise. |
|
Create a tensor or an array from another tensor, an array or from a list/tuple of tensors or arrays. |
|
Broadcast Array or Tensor to a new shape. |
|
Join a sequence of arrays along an existing axis. |
|
Cosine element-wise. |
|
Hyperbolic cosine, element-wise. |
|
Return specified diagonals. |
|
Matrix product of two arrays. |
|
Return a new Tensor with old-dual data as new-real values, with ntrax derived by like. |
|
Einsum limited to one, two, three or four operands. |
|
Calculate the exponential of all elements in the input array. |
|
Evaluate the Tensor returned by an external scalar-valued function, evaluated at a given value x, with provided gradient and hessian which operates on the values of a tensor and optional arguments. |
|
Stack arrays in sequence horizontally (column wise). |
|
Mask-based Condition for arrays and tensors. |
|
Natural logarithm, element-wise. |
|
Return the base 10 logarithm of the input array, element-wise. |
|
Matrix product of two arrays. |
|
Element-wise maximum of array elements. |
|
Element-wise minimum of array elements. |
|
Return a contiguous flattened array. |
|
Return a new Tensor with old-real data as new-dual values. |
|
Repeat elements of an array. |
|
Gives a new shape to an array without changing its data. |
|
Returns an element-wise indication of the sign of a number. |
|
Trigonometric sine, element-wise. |
|
Hyperbolic sine, element-wise. |
|
Split an array into multiple sub-arrays as views into ary. |
|
Remove axes of length one. |
|
Return the non-negative square-root of an array, element-wise. |
|
Join a sequence of arrays along a new axis. |
|
Sum of array elements over a given axis. |
|
Compute tangent element-wise. |
|
Compute hyperbolic tangent element-wise. |
|
Construct an array by repeating A the number of times given by reps. |
|
Return the sum along diagonals of the array. |
|
Returns an array with axes transposed. |
|
Stack arrays in sequence vertically (row wise). |
Detailed API Reference
- tensortrax.math.array(object, dtype=None, like=None, shape=None)[source]#
Create a tensor or an array from another tensor, an array or from a list/tuple of tensors or arrays.
- Parameters:
object (tensortrax.Tensor, array_like, list or tuple of tensortrax.Tensor or list or tuple of array_like) – The object from which the array is created.
dtype (data-type or None, optional) – Data-type of the array(s). Default is None.
like (tensortrax.Tensor or None, optional) – Reference tensor for shape and (number of) trailing axes. Default is None. Only considered if
objectis not a tensor.shape (tuple of int or None, optional) – The shape of the data of the tensor (without shape of trailing axes). If None, the shape is taken from
like. . Only considered ifobjectis not a tensor.
- Returns:
The return type depends on the type of
object.- Return type:
tensortrax.Tensor or ndarray
- tensortrax.math.concatenate(arrays, axis=0)[source]#
Join a sequence of arrays along an existing axis.
- tensortrax.math.dot(A, B)#
Matrix product of two arrays.
- tensortrax.math.dual_to_real(A, like=None)[source]#
Return a new Tensor with old-dual data as new-real values, with ntrax derived by like.
- tensortrax.math.einsum(subscripts, *operands)[source]#
Einsum limited to one, two, three or four operands.
- tensortrax.math.external(x, function, gradient, hessian, indices='ij', *args, **kwargs)[source]#
Evaluate the Tensor returned by an external scalar-valued function, evaluated at a given value x, with provided gradient and hessian which operates on the values of a tensor and optional arguments. All math methods inside the external function/gradient/hessian must handle arbitrary number of elementwise-operating trailing axes.
- tensortrax.math.real_to_dual(A, x, mul=None)[source]#
Return a new Tensor with old-real data as new-dual values.
\[ \begin{align}\begin{aligned}\delta W(x) &= A(x)\ \delta x\\\Delta \delta W(x) &= \Delta A(x)\ \delta x + A(x)\ \Delta \delta x\end{aligned}\end{align} \]
- tensortrax.math.reshape(A, shape, order='C')[source]#
Gives a new shape to an array without changing its data.
- tensortrax.math.split(ary, indices_or_sections, axis=0)[source]#
Split an array into multiple sub-arrays as views into ary.