lenskit.data.matrix.SparseRowArray#
- class lenskit.data.matrix.SparseRowArray#
Bases:
pyarrow.ExtensionArrayAn array of sparse rows (a compressed sparse row matrix).
Stability: Internal
This API is at the internal or experimental stability level: it may change at any time, and breaking changes will not necessarily be described in the release notes. See Stability Levels for details.
- type: SparseRowType | SparseIndexListType#
- classmethod from_arrays(offsets, indices, values=None, *, shape=None)#
- Parameters:
- Return type:
- classmethod from_array(array, dimension=None)#
Interpret an Arrow array as a sparse row array, if possible. Handles legacy layouts without the extension types.
- Parameters:
array (pyarrow.Array) – The array to convert.
dimension (int | None) – The dimensionality of the sparse rows, if known from an external source.
- Return type:
- classmethod from_scipy(matrix, *, values=True, large=None)#
Create a sparse row array from a SciPy sparse matrix.
- Parameters:
csr – The SciPy sparse matrix (in CSR format).
values (bool) – Whether to include the values or create a structure-only array.
large (bool | None) –
Trueto force creation of apa.LargeListArray.matrix (scipy.sparse.sparray)
- Returns:
The sparse row array.
- Return type:
- to_scipy()#
Convert this sparse row array to a SciPy sparse array.
- Return type:
scipy.sparse.csr_array[Any, tuple[int, int]]
- to_torch()#
Convert this sparse row array to a Torch sparse tensor.
- Return type:
- to_coo()#
Convert this array to table representing the array in COO format.
- Return type:
- property offsets: pyarrow.Int32Array#
- Return type:
- property indices: pyarrow.Int32Array#
- Return type:
- property values: pyarrow.Array | None#
- Return type:
pyarrow.Array | None
- structure()#
Get the structure of this matrix (without values).
- Return type:
- transpose()#
Get the transpose of this sparse matrix.
- Return type: