pyarrow.SparseCOOTensor#
- class pyarrow.SparseCOOTensor#
Bases:
_WeakrefableA 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.
- dim_names#
- equals(self, SparseCOOTensor other)#
Return true if sparse tensors contains exactly equal data.
- Parameters:
- other
SparseCOOTensor The other tensor to compare for equality.
- other
- classmethod from_dense_numpy(cls, obj, dim_names=None)#
Convert numpy.ndarray to arrow::SparseCOOTensor
- 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, coords, shape, dim_names=None)#
Create arrow::SparseCOOTensor from numpy.ndarrays
- Parameters:
- data
numpy.ndarray Data used to populate the rows.
- coords
numpy.ndarray Coordinates of the data.
- shape
tuple Shape of the tensor.
- dim_names
list, optional Names of the dimensions.
- data
- static from_pydata_sparse(obj, dim_names=None)#
Convert pydata/sparse.COO to arrow::SparseCOOTensor.
- Parameters:
- obj
pydata.sparse.COO The sparse multidimensional array that should be converted.
- dim_names
list, optional Names of the dimensions.
- obj
- static from_scipy(obj, dim_names=None)#
Convert scipy.sparse.coo_array or scipy.sparse.coo_matrix to arrow::SparseCOOTensor
- Parameters:
- obj
scipy.sparse.coo_arrayorscipy.sparse.coo_matrix The scipy array or matrix that should be converted.
- dim_names
list, optional Names of the dimensions.
- obj
- static from_tensor(obj)#
Convert arrow::Tensor to arrow::SparseCOOTensor.
- Parameters:
- obj
Tensor The tensor that should be converted.
- obj
- 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#