jina.types.ndarray.sparse.numpy

class jina.types.ndarray.sparse.numpy.SparseNdArray(*args, **kwargs)[source]

Bases: jina.types.ndarray.sparse.BaseSparseNdArray

Numpy powered sparse ndarray, it uses nonzero.

Note

This always take a dense np.ndarray and return a np.ndarray. It only store nonzero data in sparse format, it does not keep a sparse representation in memory.

Parameters

proto – the protobuf message, when not given then create a new one via get_null_proto()

sparse_constructor(indices, values, shape)[source]

Sparse NdArray constructor, must be implemented by subclass

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

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

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

Return type

ndarray

Returns

sparse_parser(value)[source]

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

Parameters

value (ndarray) – the sparse ndarray

Returns

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