docarray.ndarray package

Module contents

class docarray.ndarray.NdArray(obj=None, copy=False)[source]

Bases: docarray.base.BaseProtoView

A base class for containing the protobuf message of NdArray. It defines interfaces for easier get/set value.

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()

numpy()[source]

Return the value always in numpy.ndarray regardless the framework type.

Return type

ndarray

Returns

the value in numpy.ndarray.

static ravel(value, docs, field)[source]

Ravel value into doc.field of each documents

Parameters
  • docs (Iterator[ForwardRef]) – the docs to set

  • field (str) – the field of the doc to set

  • value (ArrayType) – the value to be set on doc.field

Return type

None

static unravel(protos)[source]

Unravel many ndarray-like proto in one-shot, by following the shape and dtype of the first proto.

Parameters

protos (Sequence[NdArrayProto]) – a list of ndarray protos

Return type

ArrayType

Returns

a framework ndarray

property value: ArrayType

Return the value in original framework type

Return type

ArrayType

Returns

the value of in numpy, scipy, tensorflow, pytorch type.

property is_sparse: bool

Check if the object represents a sparse ndarray.

Return type

bool

Returns

True if the underlying ndarray is sparse

property framework: str

Return the framework name of this ndarray object

Return type

str

Returns

the framework name