qiskit_noise_learning.math.IndexedMatrix
class qiskit_noise_learning.math.IndexedMatrix(row_index_map: Mapping[RowIndex, int] | None = None, column_index_map: Mapping[ColumnIndex, int] | None = None, data: ndarray[float] | None = None)
Bases: Generic[RowIndex, ColumnIndex]
A matrix with float entries and arbitrary row and column index data.
Parameters
- row_index_map – A mapping from row indices to the integer row axes of
data. - column_index_map – A mapping from column indices to the integer column axes of
data. - data – The array for the given row and column indices.
Raises
ValueError – If the shape of data is inconsistent with the values of row_index_map or column_index_map.
__init__
__init__(row_index_map: Mapping[RowIndex, int] | None = None, column_index_map: Mapping[ColumnIndex, int] | None = None, data: ndarray[float] | None = None)
Methods
Column 1 | Column 2 |
|---|---|
__init__([row_index_map, column_index_map, data]) | |
add_rows(row_indices, rows[, tol]) | Add rows to the matrix. |
copy() | Return a copy of self. |
from_index_lists(row_indices, ...) | Construct from ordered lists of row and column indices. |
from_rows(row_indices, rows[, tol]) | Construct from row indices and their sparse IndexedVector rows. |
linearly_independent_rows([tol]) | Return a submatrix containing a maximal set of linearly independent rows. |
Attributes
Column 1 | Column 2 |
|---|---|
column_index_map | Dictionary mapping column indices to the column axis integer of self.data. |
data | The numerical data. |
rank | The rank of the matrix. |
row_index_map | Dictionary mapping row indices to the row axis integer of self.data. |
shape | The shape of the matrix. |
from_index_lists
classmethod from_index_lists(row_indices: Sequence[RowIndex], column_indices: Sequence[ColumnIndex], data: ndarray[float]) → Self
Construct from ordered lists of row and column indices.
Parameters
- row_indices – The list of row indices for the row axes of
data. - column_indices – The list of column indices for the column axes of
data. - data – The data matrix.
Returns
An IndexedMatrix whose row and column index maps are built from row_indices and column_indices.
from_rows
classmethod from_rows(row_indices: Sequence[RowIndex], rows: Sequence[IndexedVector[ColumnIndex]], tol: float = 1e-08) → Self
Construct from row indices and their sparse IndexedVector rows.
Parameters
- row_indices – The index for each row.
- rows – The sparse rows, as
IndexedVectorinstances. - tol – Tolerance below which row values are treated as
0.0.
Returns
An IndexedMatrix containing the (non-zero) rows.
row_index_map
column_index_map
Dictionary mapping column indices to the column axis integer of self.data.
data
shape
rank
Type: int
The rank of the matrix.
add_rows
add_rows(row_indices: list[RowIndex], rows: list[IndexedVector[ColumnIndex]], tol=1e-08)
Add rows to the matrix.
Parameters
- row_indices – A list of indices for the rows.
- rows – The list of rows.
- tol – Tolerance below which values in
rowsare assumed to be0.0.
Raises
- ValueError – If any row index is duplicated in
row_indicesor is already present in this instance. - ValueError – If the number of row indices does not match the number of rows.
linearly_independent_rows
linearly_independent_rows(tol=1e-08) → Self
Return a submatrix containing a maximal set of linearly independent rows.
Rows are processed in order (according to the indices in self.row_index_map): a row is kept if and only if it is linearly independent of all preceding kept rows. This guarantees earlier rows are always preferred.
Parameters
tol – The tolerance for determining linear independence based on the norm of the component of a row orthogonal to the span of preceding kept rows.
copy
copy() → Self
Return a copy of self.