pyarrow.SparseCSCMatrix#

class pyarrow.SparseCSCMatrix#

Bases: _Weakrefable

A 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.

Parameters:
iint

The physical index of the tensor dimension.

Returns:
str
dim_names#
equals(self, SparseCSCMatrix other)#

Return true if sparse tensors contains exactly equal data

Parameters:
otherSparseCSCMatrix

The other tensor to compare for equality.

classmethod from_dense_numpy(cls, obj, dim_names=None)#

Convert numpy.ndarray to arrow::SparseCSCMatrix

Parameters:
objnumpy.ndarray

Data used to populate the rows.

dim_nameslist[str], optional

Names of the dimensions.

Returns:
pyarrow.SparseCSCMatrix
static from_numpy(data, indptr, indices, shape, dim_names=None)#

Create arrow::SparseCSCMatrix from numpy.ndarrays

Parameters:
datanumpy.ndarray

Data used to populate the sparse matrix.

indptrnumpy.ndarray

Range of the rows, The i-th row spans from indptr[i] to indptr[i+1] in the data.

indicesnumpy.ndarray

Column indices of the corresponding non-zero values.

shapetuple

Shape of the matrix.

dim_nameslist, optional

Names of the dimensions.

static from_scipy(obj, dim_names=None)#

Convert scipy.sparse.csc_array or scipy.sparse.csc_matrix to arrow::SparseCSCMatrix

Parameters:
objscipy.sparse.csc_array or scipy.sparse.csc_matrix

The scipy matrix that should be converted.

dim_nameslist, optional

Names of the dimensions.

static from_tensor(obj)#

Convert arrow::Tensor to arrow::SparseCSCMatrix

Parameters:
objTensor

The dense tensor that should be converted.

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#