pyarrow.SparseCSRMatrix#
- class pyarrow.SparseCSRMatrix#
Bases:
_WeakrefableA sparse CSR (Compressed Sparse Row) matrix.
CSR format stores a sparse matrix by compressing the row information. It uses three arrays: data (non-zero values), indices (column indices), and indptr (row pointers that indicate where each row starts in the data array).
Examples
>>> import pyarrow as pa >>> import numpy as np >>> dense_matrix = np.array([[1, 0, 2], [0, 0, 3]], dtype=np.float64) >>> sparse_csr = pa.SparseCSRMatrix.from_dense_numpy(dense_matrix) >>> sparse_csr <pyarrow.SparseCSRMatrix> type: double shape: (2, 3)
- __init__(*args, **kwargs)#
Methods
__init__(*args, **kwargs)dim_name(self, i)Returns the name of the i-th tensor dimension.
equals(self, SparseCSRMatrix other)Return true if sparse tensors contains exactly equal data.
from_dense_numpy(cls, obj[, dim_names])Convert numpy.ndarray to arrow::SparseCSRMatrix
from_numpy(data, indptr, indices, shape[, ...])Create arrow::SparseCSRMatrix from numpy.ndarrays.
from_scipy(obj[, dim_names])Convert scipy.sparse.csr_array or scipy.sparse.csr_matrix to arrow::SparseCSRMatrix.
from_tensor(obj)Convert arrow::Tensor to arrow::SparseCSRMatrix.
to_numpy(self)Convert arrow::SparseCSRMatrix to numpy.ndarrays with zero copy.
to_scipy(self)Convert arrow::SparseCSRMatrix to scipy.sparse.csr_array.
to_tensor(self)Convert arrow::SparseCSRMatrix to arrow::Tensor.
Attributes
- dim_name(self, i)#
Returns the name of the i-th tensor dimension.
- dim_names#
- equals(self, SparseCSRMatrix other)#
Return true if sparse tensors contains exactly equal data.
- Parameters:
- other
SparseCSRMatrix The other tensor to compare for equality.
- other
- classmethod from_dense_numpy(cls, obj, dim_names=None)#
Convert numpy.ndarray to arrow::SparseCSRMatrix
- Parameters:
- obj
numpy.ndarray The dense numpy array that should be converted.
- dim_names
list, optional The names of the dimensions.
- obj
- Returns:
- static from_numpy(data, indptr, indices, shape, dim_names=None)#
Create arrow::SparseCSRMatrix from numpy.ndarrays.
- Parameters:
- data
numpy.ndarray Data used to populate the sparse matrix.
- indptr
numpy.ndarray Range of the rows, The i-th row spans from indptr[i] to indptr[i+1] in the data.
- indices
numpy.ndarray Column indices of the corresponding non-zero values.
- shape
tuple Shape of the matrix.
- dim_names
list, optional Names of the dimensions.
- data
- static from_scipy(obj, dim_names=None)#
Convert scipy.sparse.csr_array or scipy.sparse.csr_matrix to arrow::SparseCSRMatrix.
- Parameters:
- obj
scipy.sparse.csr_arrayorscipy.sparse.csr_matrix The scipy matrix that should be converted.
- dim_names
list, optional Names of the dimensions.
- obj
- static from_tensor(obj)#
Convert arrow::Tensor to arrow::SparseCSRMatrix.
- Parameters:
- obj
Tensor The dense tensor that should be converted.
- obj
- is_mutable#
- ndim#
- non_zero_length#
- shape#
- size#
- to_numpy(self)#
Convert arrow::SparseCSRMatrix to numpy.ndarrays with zero copy.
- to_scipy(self)#
Convert arrow::SparseCSRMatrix to scipy.sparse.csr_array.
- to_tensor(self)#
Convert arrow::SparseCSRMatrix to arrow::Tensor.
- type#