jina.types.ndarray.sparse

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

Bases: jina.types.ndarray.BaseNdArray

The base class for SparseNdArray.

Do not use this class directly. Subclass should be used.

Parameters

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

null_proto()[source]

Get the new protobuf representation

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

~AnySparseNdArray

Returns

sparse_parser(value)[source]

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

Parameters

value (~AnySparseNdArray) – the sparse ndarray

Return type

Dict[str, Union[ForwardRef, List[int]]]

Returns

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

property value

Return the value of the ndarray, in numpy, scipy, tensorflow, pytorch type

Return type

~AnySparseNdArray