pyarrow.SparseCSCMatrix#
- class pyarrow.SparseCSCMatrix#
Bases:
_WeakrefableA sparse CSC (Compressed Sparse Column) matrix.
CSC format stores a sparse matrix by compressing the column information. It uses three arrays: data (non-zero values), indices (row indices), and indptr (column pointers that indicate where each column starts in the data array). CSC is the transpose of CSR format.
Examples
>>> import pyarrow as pa >>> import numpy as np >>> dense_matrix = np.array([[1, 0, 2], [0, 0, 3]], dtype=np.float64) >>> sparse_csc = pa.SparseCSCMatrix.from_dense_numpy(dense_matrix) >>> sparse_csc <pyarrow.SparseCSCMatrix> 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, SparseCSCMatrix other)Return true if sparse tensors contains exactly equal data
from_dense_numpy(cls, obj[, dim_names])Convert numpy.ndarray to arrow::SparseCSCMatrix
from_numpy(data, indptr, indices, shape[, ...])Create arrow::SparseCSCMatrix from numpy.ndarrays
from_scipy(obj[, dim_names])Convert scipy.sparse.csc_array or scipy.sparse.csc_matrix to arrow::SparseCSCMatrix
from_tensor(obj)Convert arrow::Tensor to arrow::SparseCSCMatrix
to_numpy(self)Convert arrow::SparseCSCMatrix to numpy.ndarrays with zero copy
to_scipy(self)Convert arrow::SparseCSCMatrix to scipy.sparse.csc_array
to_tensor(self)Convert arrow::SparseCSCMatrix to arrow::Tensor
Attributes
- dim_name(self, i)#
Returns the name of the i-th tensor dimension.
- dim_names#
- equals(self, SparseCSCMatrix other)#
Return true if sparse tensors contains exactly equal data
- Parameters:
- other
SparseCSCMatrix The other tensor to compare for equality.
- other
- classmethod from_dense_numpy(cls, obj, dim_names=None)#
Convert numpy.ndarray to arrow::SparseCSCMatrix
- Parameters:
- obj
numpy.ndarray Data used to populate the rows.
- dim_names
list[str], optional Names of the dimensions.
- obj
- Returns:
- static from_numpy(data, indptr, indices, shape, dim_names=None)#
Create arrow::SparseCSCMatrix 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.csc_array or scipy.sparse.csc_matrix to arrow::SparseCSCMatrix
- Parameters:
- obj
scipy.sparse.csc_arrayorscipy.sparse.csc_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::SparseCSCMatrix
- Parameters:
- obj
Tensor The dense tensor that should be converted.
- obj
- is_mutable#
- ndim#
- non_zero_length#
- shape#
- size#
- to_numpy(self)#
Convert arrow::SparseCSCMatrix to numpy.ndarrays with zero copy
- to_scipy(self)#
Convert arrow::SparseCSCMatrix to scipy.sparse.csc_array
- to_tensor(self)#
Convert arrow::SparseCSCMatrix to arrow::Tensor
- type#