Math#

This module provides NumPy-like math functions.

abs(A)

Calculate the absolute value element-wise.

array(object[, dtype, like, shape])

Create a tensor or an array from another tensor, an array or from a list/tuple of tensors or arrays.

broadcast_to(A, shape)

Broadcast Array or Tensor to a new shape.

concatenate(arrays[, axis])

Join a sequence of arrays along an existing axis.

cos(A)

Cosine element-wise.

cosh(A)

Hyperbolic cosine, element-wise.

diagonal(A[, offset, axis1, axis2])

Return specified diagonals.

dot(A, B)

Matrix product of two arrays.

dual_to_real(A[, like])

Return a new Tensor with old-dual data as new-real values, with ntrax derived by like.

einsum(subscripts, *operands)

Einsum limited to one, two, three or four operands.

exp(A)

Calculate the exponential of all elements in the input array.

external(x, function, gradient, hessian[, ...])

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.

hstack(tup)

Stack arrays in sequence horizontally (column wise).

if_else(cond, true, false)

Mask-based Condition for arrays and tensors.

log(A)

Natural logarithm, element-wise.

log10(A)

Return the base 10 logarithm of the input array, element-wise.

matmul(A, B)

Matrix product of two arrays.

maximum(x1, x2)

Element-wise maximum of array elements.

minimum(x1, x2)

Element-wise minimum of array elements.

ravel(A[, order])

Return a contiguous flattened array.

real_to_dual(A, x[, mul])

Return a new Tensor with old-real data as new-dual values.

repeat(a, repeats[, axis])

Repeat elements of an array.

reshape(A, shape[, order])

Gives a new shape to an array without changing its data.

sign(A)

Returns an element-wise indication of the sign of a number.

sin(A)

Trigonometric sine, element-wise.

sinh(A)

Hyperbolic sine, element-wise.

split(ary, indices_or_sections[, axis])

Split an array into multiple sub-arrays as views into ary.

squeeze(A[, axis])

Remove axes of length one.

sqrt(A)

Return the non-negative square-root of an array, element-wise.

stack(arrays[, axis])

Join a sequence of arrays along a new axis.

sum(A[, axis])

Sum of array elements over a given axis.

tan(A)

Compute tangent element-wise.

tanh(A)

Compute hyperbolic tangent element-wise.

tile(A, reps)

Construct an array by repeating A the number of times given by reps.

trace(A)

Return the sum along diagonals of the array.

transpose(A)

Returns an array with axes transposed.

vstack(tup)

Stack arrays in sequence vertically (row wise).

Detailed API Reference

tensortrax.math.abs(A)[source]#

Calculate the absolute value element-wise.

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 object is 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 if object is not a tensor.

Returns:

The return type depends on the type of object.

Return type:

tensortrax.Tensor or ndarray

tensortrax.math.broadcast_to(A, shape)[source]#

Broadcast Array or Tensor to a new shape.

tensortrax.math.concatenate(arrays, axis=0)[source]#

Join a sequence of arrays along an existing axis.

tensortrax.math.cos(A)[source]#

Cosine element-wise.

tensortrax.math.cosh(A)[source]#

Hyperbolic cosine, element-wise.

tensortrax.math.diagonal(A, offset=0, axis1=0, axis2=1)[source]#

Return specified diagonals.

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.exp(A)[source]#

Calculate the exponential of all elements in the input array.

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.hstack(tup)[source]#

Stack arrays in sequence horizontally (column wise).

tensortrax.math.if_else(cond, true, false)[source]#

Mask-based Condition for arrays and tensors.

tensortrax.math.log(A)[source]#

Natural logarithm, element-wise.

tensortrax.math.log10(A)[source]#

Return the base 10 logarithm of the input array, element-wise.

tensortrax.math.matmul(A, B)[source]#

Matrix product of two arrays.

tensortrax.math.maximum(x1, x2)[source]#

Element-wise maximum of array elements.

tensortrax.math.minimum(x1, x2)[source]#

Element-wise minimum of array elements.

tensortrax.math.ravel(A, order='C')[source]#

Return a contiguous flattened array.

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.repeat(a, repeats, axis=None)[source]#

Repeat elements of an array.

tensortrax.math.reshape(A, shape, order='C')[source]#

Gives a new shape to an array without changing its data.

tensortrax.math.sign(A)[source]#

Returns an element-wise indication of the sign of a number.

tensortrax.math.sin(A)[source]#

Trigonometric sine, element-wise.

tensortrax.math.sinh(A)[source]#

Hyperbolic sine, element-wise.

tensortrax.math.split(ary, indices_or_sections, axis=0)[source]#

Split an array into multiple sub-arrays as views into ary.

tensortrax.math.sqrt(A)[source]#

Return the non-negative square-root of an array, element-wise.

tensortrax.math.squeeze(A, axis=None)[source]#

Remove axes of length one.

tensortrax.math.stack(arrays, axis=0)[source]#

Join a sequence of arrays along a new axis.

tensortrax.math.sum(A, axis=0)[source]#

Sum of array elements over a given axis.

tensortrax.math.tan(A)[source]#

Compute tangent element-wise.

tensortrax.math.tanh(A)[source]#

Compute hyperbolic tangent element-wise.

tensortrax.math.tile(A, reps)[source]#

Construct an array by repeating A the number of times given by reps.

tensortrax.math.trace(A)[source]#

Return the sum along diagonals of the array.

tensortrax.math.transpose(A)[source]#

Returns an array with axes transposed.

tensortrax.math.vstack(tup)[source]#

Stack arrays in sequence vertically (row wise).