jina.types.ndarray.sparse.scipy module

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
  • proto (Optional[SparseNdArrayProto]) – the protobuf message, when not given then create a new one via get_null_proto()

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

Set constructor method.

sparse_constructor(indices, values, shape)[source]

Sparse NdArray constructor for scipy.sparse.spmatrix.

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 sparse array

Return type

scipy.sparse.spmatrix

Returns

SparseTensor

sparse_parser(value)[source]

Parse a scipy.sparse.spmatrix to indices, values and shape.

Parameters

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

Returns

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