pyarrow.SparseCOOTensor#

class pyarrow.SparseCOOTensor#

Bases: _Weakrefable

A sparse COO (COOrdinate) tensor.

COO format stores a sparse tensor as a collection of (indices, values) pairs. The indices specify the coordinates of non-zero elements, and the values contain the actual data at those coordinates.

Examples

>>> import pyarrow as pa
>>> import numpy as np
>>> dense_tensor = np.array([[0, 1, 0], [2, 0, 3]], dtype=np.float32)
>>> sparse_coo = pa.SparseCOOTensor.from_dense_numpy(dense_tensor)
>>> sparse_coo
<pyarrow.SparseCOOTensor>
type: float
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, SparseCOOTensor other)

Return true if sparse tensors contains exactly equal data.

from_dense_numpy(cls, obj[, dim_names])

Convert numpy.ndarray to arrow::SparseCOOTensor

from_numpy(data, coords, shape[, dim_names])

Create arrow::SparseCOOTensor from numpy.ndarrays

from_pydata_sparse(obj[, dim_names])

Convert pydata/sparse.COO to arrow::SparseCOOTensor.

from_scipy(obj[, dim_names])

Convert scipy.sparse.coo_array or scipy.sparse.coo_matrix to arrow::SparseCOOTensor

from_tensor(obj)

Convert arrow::Tensor to arrow::SparseCOOTensor.

to_numpy(self)

Convert arrow::SparseCOOTensor to numpy.ndarrays with zero copy.

to_pydata_sparse(self)

Convert arrow::SparseCOOTensor to pydata/sparse.COO.

to_scipy(self)

Convert arrow::SparseCOOTensor to scipy.sparse.coo_array.

to_tensor(self)

Convert arrow::SparseCOOTensor 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, SparseCOOTensor other)#

Return true if sparse tensors contains exactly equal data.

Parameters:
otherSparseCOOTensor

The other tensor to compare for equality.

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

Convert numpy.ndarray to arrow::SparseCOOTensor

Parameters:
objnumpy.ndarray

Data used to populate the rows.

dim_nameslist[str], optional

Names of the dimensions.

Returns:
pyarrow.SparseCOOTensor
static from_numpy(data, coords, shape, dim_names=None)#

Create arrow::SparseCOOTensor from numpy.ndarrays

Parameters:
datanumpy.ndarray

Data used to populate the rows.

coordsnumpy.ndarray

Coordinates of the data.

shapetuple

Shape of the tensor.

dim_nameslist, optional

Names of the dimensions.

static from_pydata_sparse(obj, dim_names=None)#

Convert pydata/sparse.COO to arrow::SparseCOOTensor.

Parameters:
objpydata.sparse.COO

The sparse multidimensional array that should be converted.

dim_nameslist, optional

Names of the dimensions.

static from_scipy(obj, dim_names=None)#

Convert scipy.sparse.coo_array or scipy.sparse.coo_matrix to arrow::SparseCOOTensor

Parameters:
objscipy.sparse.coo_array or scipy.sparse.coo_matrix

The scipy array or matrix that should be converted.

dim_nameslist, optional

Names of the dimensions.

static from_tensor(obj)#

Convert arrow::Tensor to arrow::SparseCOOTensor.

Parameters:
objTensor

The tensor that should be converted.

has_canonical_format#
is_mutable#
ndim#
non_zero_length#
shape#
size#
to_numpy(self)#

Convert arrow::SparseCOOTensor to numpy.ndarrays with zero copy.

to_pydata_sparse(self)#

Convert arrow::SparseCOOTensor to pydata/sparse.COO.

to_scipy(self)#

Convert arrow::SparseCOOTensor to scipy.sparse.coo_array.

to_tensor(self)#

Convert arrow::SparseCOOTensor to arrow::Tensor.

type#