pint.pint_matrix.PintMatrix

class pint.pint_matrix.PintMatrix(matrix, axis_labels)[source]

Bases: object

PINT matrix is a base class for PINT fitters matrix.

Parameters:
  • data (numpy.ndarray) – Matrix data.

  • axis_labels (list of dictionary) – The labels of the axes. Each list element contains the names and indices of the labels for the dimension. [{dim0_label0: (start, end, unit), dim0_label1:(start, end, unit)}, {dim1_label0:…}] The start and end follows the python slice convention (i.e., end = size + 1).

Note

TODO: 1. add index to label mapping

Methods

append_along_axis(pint_matrix, axis)

Append one pint matrix on a given axis.

diag([k])

Extract a diagonal.

get_axis_labels(axis)

Get the axis labels for the specified axis

get_label(label[, axis])

Get the label entry and its dimension.

get_label_along_axis(axis, label_name)

Get the request label from on axis.

get_label_matrix(labels)

Get a sub-matrix data according to the given labels.

get_label_names([axis])

Return only the names of the labels along the specified axis if requested.

get_label_size(label[, axis])

Get the size of the a label for all axes, or just the specified axis.

get_label_slice(labels)

Return the given label slices.

get_unique_label_names()

Return all unique label names (there may be duplications between axes).

map_labels()

match_labels_along_axis(pint_matrix, axis)

Match one axis' labels index between the current matrix and input pint matrix.

Attributes

label_units

labels

ndim

shape

diag(k=0)[source]

Extract a diagonal.

Parameters:

k (int (optional)) – Diagonal in question. The default is 0. Use k>0 for diagonals above the main diagonal, and k<0 for diagonals below the main diagonal.

Returns:

out – The extracted diagonal.

Return type:

ndarray

get_label_names(axis=None)[source]

Return only the names of the labels along the specified axis if requested.

Parameters:

axis (int (optional)) – axis for the label lookup

Returns:

labels

Return type:

list of label names for all dimensions, or just along the specified axis

get_unique_label_names()[source]

Return all unique label names (there may be duplications between axes).

Returns:

  • labels (set of unique label names across all dimensions)

  • TODO (preserve order?)

get_label_size(label, axis=None)[source]

Get the size of the a label for all axes, or just the specified axis.

Parameters:
  • label (str) – Name of the label.

  • axis (int (optional)) – axis for the label lookup

Returns:

sizes

Return type:

list of (start,stop) indices for the given label across each dimension

get_axis_labels(axis)[source]

Get the axis labels for the specified axis

Parameters:

axis (int) – axis for the label lookup

Returns:

labels

Return type:

list of (name, (start,stop,unit) for the given axis

get_label(label, axis=None)[source]

Get the label entry and its dimension. If axis is specified, will only be along that axis

Parameters:
  • label (str) – label to lookup

  • axis (int, optional) – axis for the label lookup

Returns:

labels

Return type:

list of (name, axis, start,stop,unit) for the given label

get_label_along_axis(axis, label_name)[source]

Get the request label from on axis.

DEPRECATED - use get_label(…, axis=axis)

get_label_slice(labels)[source]

Return the given label slices.

Parameters:

labels (list of str) – labels to lookup

Returns:

slice, labels

Return type:

slice into original matrix and labels of new (sliced) matrix

get_label_matrix(labels)[source]

Get a sub-matrix data according to the given labels.

Parameters:

labels (list of str) – labels to lookup

Returns:

PintMatrix

Return type:

new matrix with only the specified labels (or relevant subclass)

match_labels_along_axis(pint_matrix, axis)[source]

Match one axis’ labels index between the current matrix and input pint matrix.

The labels will be matched along axes, not cross the axes.

Parameters:
  • pint_matrix (PintMatrix object or its sub-classes.) – The input pint matrix for label matching.

  • axis (int) – The matching axis.

Returns:

  • Index map between the current labels and input matrix labels along

  • axis.

append_along_axis(pint_matrix, axis)[source]

Append one pint matrix on a given axis.