Vector#

brainmaze_utils.vector.get_mutual_vectors(x, y=None)#

Compute all pairwise difference vectors between points.

Row i * n_points + j of the result is x[i] - x[j] (including i == j).

Parameters:
  • x (numpy.ndarray) – Array of vectors with shape (n_points, n_dimensions)

  • y (array-like, optional) – Labels for the vectors. If provided, returns labels for each pair.

Returns:

If y is None: array of all pairwise difference vectors If y is provided: tuple of (difference vectors, pair labels)

Return type:

numpy.ndarray or tuple

brainmaze_utils.vector.get_rot_2d(an)#

Get 2D rotation matrix for a given angle.

Parameters:

an (float) – Rotation angle in degrees

Returns:

2x2 rotation matrix

Return type:

numpy.ndarray

brainmaze_utils.vector.get_rot_3d(an)#

Get 3D rotation matrices for given angles around x, y, and z axes.

Parameters:

an (array-like) – Array of 3 rotation angles [x, y, z] in degrees

Returns:

List of three 3x3 rotation matrices [Rx, Ry, Rz]

Return type:

list

brainmaze_utils.vector.get_rot_3d_x(an)#

Get 3D rotation matrix for rotation around the x-axis.

Parameters:

an (float) – Rotation angle in degrees

Returns:

3x3 rotation matrix for x-axis rotation

Return type:

numpy.ndarray

brainmaze_utils.vector.get_rot_3d_y(an)#

Get 3D rotation matrix for rotation around the y-axis.

Parameters:

an (float) – Rotation angle in degrees

Returns:

3x3 rotation matrix for y-axis rotation

Return type:

numpy.ndarray

brainmaze_utils.vector.get_rot_3d_z(an)#

Get 3D rotation matrix for rotation around the z-axis.

Parameters:

an (float) – Rotation angle in degrees

Returns:

3x3 rotation matrix for z-axis rotation

Return type:

numpy.ndarray

brainmaze_utils.vector.rotate(x, angl)#

Rotate vectors by specified angle(s) around their mean.

Parameters:
  • x (numpy.ndarray) – Array of vectors with shape (n_points, 2) or (n_points, 3)

  • angl (float or array-like) – For 2D: single rotation angle in degrees For 3D: array of 3 rotation angles [x, y, z] in degrees

Returns:

Rotated vectors (new array; x is not modified).

Return type:

numpy.ndarray

Notes

Direction convention: points are row vectors multiplied from the right by the matrices of get_rot_2d() / get_rot_3d() (x @ R). This is the transpose of the usual column-vector convention, so in 2-D a positive angle rotates clockwise. Rotation is about the mean of the points (a single point is therefore unchanged): [[0, 0], [2, 0]] rotated by +90 deg becomes [[1, 1], [1, -1]]. In 3-D the rotations are applied in the order x, y, z, each with the same row-vector convention. Negate the angle(s) for counter-clockwise rotation.

brainmaze_utils.vector.scale(x, m)#

Scale vectors around their mean by given factors.

Parameters:
  • x (numpy.ndarray) – Array of vectors with shape (n_points, n_dimensions)

  • m (array-like) – Scale factors for each dimension

Returns:

Scaled vectors

Return type:

numpy.ndarray

brainmaze_utils.vector.translate(x, m)#

Translate vectors by given offsets.

Parameters:
  • x (numpy.ndarray) – Array of vectors with shape (n_points, n_dimensions)

  • m (array-like) – Translation offsets for each dimension

Returns:

Translated vectors as a new array; x is not modified. The dtype is promoted as needed (an integer x translated by 0.5 gives floats).

Return type:

numpy.ndarray

Notes

Note

Changed after v2.0.0: Previously x was modified in place and the result kept x’s dtype, so integer input silently truncated fractional offsets.