lenskit.data.matrix.SparseRowArray#
- class lenskit.data.matrix.SparseRowArray#
Bases:
ExtensionArrayAn array of sparse rows (a compressed sparse row matrix).
Stability: Internal
This API is at the internal or experimental stability level: it may change at any time, and breaking changes will not necessarily be described in the release notes. See Stability Levels for details.
- __init__(*args, **kwargs)#
Methods
__init__(*args, **kwargs)buffers(self)Return a list of Buffer objects pointing to this array's physical storage.
cast(self[, target_type, safe, options, ...])Cast array values to another data type
copy_to(self, destination)Construct a copy of the array with all buffers on destination device.
dictionary_encode(self[, null_encoding])Compute dictionary-encoded representation of array.
diff(self, Array other)Compare contents of this array against another one.
drop_null(self)Remove missing values from an array.
equals(self, Array other)fill_null(self, fill_value)See
pyarrow.compute.fill_null()for usage.filter(self, mask, *[, null_selection_behavior])Select values from an array.
format(self, **kwargs)DEPRECATED, use pyarrow.Array.to_string
from_array(array[, dimension])Interpret an Arrow array as a sparse row array, if possible.
from_arrays(offsets, indices[, values, shape])from_buffers(DataType type, length, buffers)Construct an Array from a sequence of buffers.
from_pandas(obj[, mask, type])Convert pandas.Series to an Arrow Array.
from_scipy(matrix, *[, values, large])Create a sparse row array from a SciPy sparse matrix.
from_storage(BaseExtensionType typ, ...)Construct ExtensionArray from type and storage array.
get_total_buffer_size(self)The sum of bytes in each buffer referenced by the array.
index(self, value[, start, end, memory_pool])Find the first index of a value.
is_nan(self)Return BooleanArray indicating the NaN values.
is_null(self, *[, nan_is_null])Return BooleanArray indicating the null values.
is_valid(self)Return BooleanArray indicating the non-null values.
row_extent(row)Get the start and end of a row.
row_indices(row)Get the index array for a compressed sparse row.
slice(self[, offset, length])Compute zero-copy slice of this array.
sort(self[, order])Sort the Array
Get the structure of this matrix (without values).
sum(self, **kwargs)Sum the values in a numerical array.
take(self, indices)Select values from an array.
to_coo()Convert this array to table representing the array in COO format.
to_numpy(self[, zero_copy_only, writable])Return a NumPy view or copy of this array.
to_pandas(self[, memory_pool, categories, ...])Convert to a pandas-compatible NumPy array or DataFrame, as appropriate
to_pylist(self, *[, maps_as_pydicts])Convert to a list of native Python objects.
to_scipy()Convert this sparse row array to a SciPy sparse array.
to_string(self, *, int indent=2, ...)Render a "pretty-printed" string representation of the Array.
to_torch()Convert this sparse row array to a Torch sparse tensor.
tolist(self)Alias of to_pylist for compatibility with NumPy.
Get the transpose of this sparse matrix.
unique(self)Compute distinct elements in array.
validate(self, *[, full])Perform validation checks.
value_counts(self)Compute counts of unique elements in array.
view(self, target_type)Return zero-copy "view" of array as another data type.
Attributes
device_typeThe device type where the array resides.
Get the number of columns in the sparse matrix.
has_valuesindicesis_cpuWhether the array is CPU-accessible.
nbytesTotal number of bytes consumed by the elements of the array.
null_countoffsetA relative position into another array's data.
offsetsshapestatisticsStatistics of the array.
storagetypevalues- classmethod from_array(array, dimension=None)#
Interpret an Arrow array as a sparse row array, if possible. Handles legacy layouts without the extension types.
- Parameters:
- Return type:
- classmethod from_scipy(matrix, *, values=True, large=None)#
Create a sparse row array from a SciPy sparse matrix.
- Parameters:
- Returns:
The sparse row array.
- Return type:
- to_scipy()#
Convert this sparse row array to a SciPy sparse array.
- structure()#
Get the structure of this matrix (without values).
- Return type:
- transpose()#
Get the transpose of this sparse matrix.
- Return type: