jina.types.ndarray.sparse.scipy

class jina.types.ndarray.sparse.scipy.SparseNdArray(proto=None, sp_format='coo', *args, **kwargs)[source]

Bases: jina.types.ndarray.sparse.BaseSparseNdArray

Scipy powered sparse ndarray

Warning

scipy only supports ndim=2

Parameters
  • sp_format (str) – the sparse format of the scipy matrix. one of ‘coo’, ‘bsr’, ‘csc’, ‘csr’

  • args

  • kwargs

sparse_constructor(indices, values, shape)[source]

Sparse NdArray constructor, must be implemented by subclass

Parameters
  • indices (np.ndarray) – the indices of the sparse array

  • values (np.ndarray) – the values of the sparse array

  • shape (List[int]) – the shape of the dense array

Return type

scipy.sparse.spmatrix

Returns

sparse_parser(value)[source]

Parsing a Sparse NdArray to indices, values and shape, must be implemented by subclass

Parameters

value (scipy.sparse.spmatrix) – the sparse ndarray

Returns

a Dict with three entries {‘indices’: …, ‘values’:…, ‘shape’:…}