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.

Set constructor method.

sparse_constructor(indices, values, shape)[source]

Sparse NdArray constructor for np.ndarray.

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

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

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

Return type

ndarray

Returns

FloatTensor

sparse_parser(value)[source]

Parse a np.ndarray to indices, values and shape.

Parameters

value (ndarray) – the np.ndarray.

Returns

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