Helper Function and Classes

einsteinpy.symbolic.helpers.simplify_sympy_array(arr)[source]

Function to simplify sympy expression or array.

This function is explicitely defined as native simplify function within sympy stopped working with sympy version change.

Parameters:

arr (NDimArray or Expr) – Any sympy array or expression.

Returns:

Simplified sympy array or expression.

Return type:

sympy.tensor.array.ndim_array.NDimArray or Expr

einsteinpy.symbolic.helpers.sympy_to_np_array(arr)[source]

Function to convert sympy to numpy array

Parameters:

arr (NDimArray) – Sympy Array

Returns:

Numpy Array

Return type:

ndarray

class einsteinpy.symbolic.helpers.TransformationMatrix(iterable, old_coords, new_coords, shape=None, old2new=None, new2old=None, **kwargs)[source]

Bases: ImmutableDenseNDimArray

Class for defining transformation matrix for basis change of vectors and tensors.

Constructor.

Parameters:
  • iterable (iterable-object) – 2D list or array to pass a matrix.

  • old_coords (list or tuple) – list of old coordinates. For example, [x, y].

  • new_coords (list or tuple) – list of new coordinates. For example, [r, theta].

  • shape (tuple, optional) – shape of the transformation matrix. Usually, not required. Defaults to None.

  • old2new (list or tuple, optional) – List of expressions for new coordinates in terms of old coordinates. For example, [x**2+y**2, atan2(y, x)].

  • new2old (list or tuple, optional) – List of expressions for old coordinates in terms of new coordinates. For example, [r*cos(theta), r*sin(theta)].

Raises:

ValueError – Raised when tensor has a rank not equal to 2. This is because, a matrix is expected.

classmethod from_new2old(old_coords, new_coords, new2old, **kwargs)[source]

Classmethod to obtain transformation matrix from old coordinates expressed as a function of new coordinates.

Parameters:
  • old_coords (list or tuple) – list of old coordinates. For example, [x, y].

  • new_coords (list or tuple) – list of new coordinates. For example, [r, theta].

  • new2old (list or tuple, optional) – List of expressions for old coordinates in terms of new coordinates. For example, [r*cos(theta), r*sin(theta)].

inv()[source]

Returns inverse of the transformation matrix

Returns:

Inverse of the matrix.

Return type:

NDimArray