e3fp.fingerprint.array_ops module

Various array operations.

Author: Seth Axen E-mail: seth.axen@gmail.com

as_unit(v, axis=1)[source]

Return array of unit vectors parallel to vectors in v.

Parameters
  • v (ndarray of float)

  • axis (int, optional) – Axis along which to normalize length.

Returns

ndarray of float – magnitude along axis.

Return type

Unit vector of v, i.e. v divided by its

calculate_angles(vec_arr, ref, ref_norm=None)[source]

Calculate angles between vectors in vec_arr and ref vector.

If ref_norm is not provided, angle ranges between 0 and pi. If it is provided, angle ranges between 0 and 2pi. Note that if ref_norm is orthogonal to vec_arr and ref, then the angle is rotation around the axis, but if a non-orthogonal axis is provided, this may not be the case.

Parameters
  • vec_arr (Nx3 array of float) – Array of N 3D vectors.

  • ref (1x3 array of float) – Reference vector

  • ref_norm (1x3 array of float) – Normal vector.

Returns

Array of N angles

Return type

1-D array

make_distance_matrix(coords)[source]

Build pairwise distance matrix from coordinates.

Parameters

coords (ndarray of float) – an Mx3 array of cartesian coordinates.

Returns

ndarray of float

Return type

square symmetrical distance matrix

make_rotation_matrix(v0, v1)[source]

Create 3x3 matrix of rotation from v0 onto v1.

Should be used by dot(R, v0.T).T.

Parameters
  • v0 (1x3 array of float) – Initial vector before alignment.

  • v1 (1x3 array of float) – Vector to which to align v0.

make_transform_matrix(center, y=None, z=None)[source]

Make 4x4 homogenous transformation matrix.

Given Nx4 array A where A[:, 4] = 1., the transform matrix M should be used with dot(M, A.T).T. Order of operations is 1. translation, 2. align y x z plane to yz-plane 3. align y to y-axis.

Parameters
  • center (1x3 array of float) – Coordinate that should be centered after transformation.

  • y (None or 1x3 array of float) – Vector that should lie on the y-axis after transformation

  • z (None or 1x3 array of float) – Vector that after transformation should lie on yz-plane in direction of z-axis.

Returns

4x4 homogenous transformation matrix.

Return type

4x4 array of float

pad_array(a, n=1.0, axis=1)[source]

Return a with row of n appended to axis.

Parameters
  • a (ndarray) – Array to pad

  • n (float or int, optional) – Value to pad a with

  • axis (int, optional) – Axis of a to pad with n.

Returns

Padded array.

Return type

ndarray

project_to_plane(vec_arr, norm)[source]

Project array of vectors to plane with normal norm.

Parameters
  • vec_arr (Nx3 array) – Array of N 3D vectors.

  • norm (1x3 array) – Normal vector to plane.

Returns

Array of vectors projected onto plane.

Return type

Nx3 array

quaternion_to_transform_matrix(quaternion, translation=array([0., 0., 0.]))[source]

Convert quaternion to homogenous 4x4 transform matrix.

Parameters
  • quaternion (4x1 array of float) – Quaternion describing rotation after translation.

  • translation (3x1 array of float, optional) – Translation to be performed before rotation.

rotate_angles(angles, amount)[source]

Rotate angles by amount, keeping in 0 to 2pi range.

Parameters
  • angles (1-D array of float) – Angles in radians

  • amount (float) – Amount to rotate angles by

Returns

1-D array of float

Return type

Rotated angles

transform_array(transform_matrix, a)[source]

Pad an array with 1s, transform, and return with original dimensions.

Parameters
  • transform_matrix (4x4 array of float) – 4x4 homogenous transformation matrix

  • a (Nx3 array of float) – Array of 3-D coordinates.

Returns

Nx3 array of float

Return type

Transformed array

transform_matrix_to_quaternion(transform_matrix, dtype=<class 'float'>)[source]

Convert homogenous 4x4 transform matrix to quaternion.

Parameters
  • transform_matrix (4x4 array of float) – Homogenous transformation matrix.

  • dtype (numpy dtype, optional) – Datatype for returned quaternion.

unpad_array(a, axis=1)[source]

Return a with row removed along axis.

Parameters
  • a (ndarray) – Array from which to remove row

  • axis (int, optional) – Axis from which to remove row

Returns

Unpadded array.

Return type

ndarray