Tensor API
This page documents public APIs on Tensor objects. A tensor is a dataset column, accessed with ds.<tensor_name>, ds["<tensor_name>"], or ds.tensors["<tensor_name>"].
Table of Contents
Writing Data
Reading Data
- Tensor.numpy()
- Tensor.data()
- Tensor.text()
- Tensor.dict()
- Tensor.list()
- Tensor.tobytes()
- Index access
Properties
- Tensor.htype
- Tensor.dtype
- Tensor.shape
- Tensor.shape_interval
- Tensor.ndim
- Tensor.num_samples
- Tensor.sample_info
Writing Data
Tensor.append()
Signature
Tensor.append(sample, ignore_errors=False)
Parameters
- sample (
InputSample): One sample to append to this tensor. Accepted sample values depend on the tensor htype and compression configuration. - ignore_errors (
bool, optional): IfTrue, skips samples that fail during append processing where supported by the underlying chunk engine. Defaults toFalse.
Returns
- None
Example
with ds:
ds.labels.append(1)
ds.text.append("a short caption")
Tensor.extend()
Signature
Tensor.extend(samples, progressbar=False, ignore_errors=False)
Parameters
- samples (
np.ndarray,Sequence[InputSample], orTensor): Samples to append to this tensor. Passing anotherTensorcopies data from that tensor view. - progressbar (
bool, optional): IfTrue, shows progress while extending. Defaults toFalse. - ignore_errors (
bool, optional): IfTrue, continues where supported when an individual sample fails. Defaults toFalse.
Returns
- None
Example
with ds:
ds.labels.extend(np.array([0, 1, 2], dtype=np.int32))
ds.text.extend(["cat", "dog", "tree"])
Tensor.clear()
Signature
Tensor.clear()
Parameters
None.
Returns
- None
Example
with ds:
ds.temp_values.clear()
Index Assignment
Signature
tensor[item] = value
Parameters
- item (
intorslice): Sample position or contiguous sample range to update. - value (
Any): Replacement sample or samples. When assigning aTensor, MULLER reads it withvalue.numpy(aslist=True)before updating.
Returns
- None
Notes
- Assignment updates existing samples and marks the dataset as no longer append-only.
- If random assignment is enabled in MULLER constants, assigning to an integer index beyond the current length pads missing samples before appending the new value.
Example
with ds:
ds.labels[0] = 5
ds.labels[1:3] = np.array([6, 7], dtype=np.int32)
Reading Data
Tensor.numpy()
Signature
Tensor.numpy(aslist=False, fetch_chunks=False, max_workers=MAX_WORKERS_FOR_CHUNK_ENGINE)
Parameters
- aslist (
bool, optional): IfTrue, returns a list ofnp.ndarrayobjects. This is useful for dynamically shaped tensors. IfFalse, returns a singlenp.ndarrayunless the selected samples cannot be represented as one regular array. Defaults toFalse. - fetch_chunks (
bool, optional): IfTrue, fetches complete chunks from storage. IfFalse, fetches only required bytes where possible. MULLER may still fetch chunks internally for iteration, chunk-compressed tensors, or large chunks. Defaults toFalse. - max_workers (
int, optional): Maximum worker count used by the chunk engine while reading. Defaults toMAX_WORKERS_FOR_CHUNK_ENGINE.
Returns
- np.ndarray or List[np.ndarray]
Notes
Tensor.numpy()does not accept anasrowparameter.- For tensors with htype
polygon,aslistis always treated asTrue.
Example
arr = ds.labels[:10].numpy()
samples = ds.images[:10].numpy(aslist=True)
Tensor.data()
Signature
Tensor.data(aslist=False, fetch_chunks=False)
Parameters
- aslist (
bool, optional): Passed toTensor.numpy()for htypes that return numpy-backed values. Defaults toFalse. - fetch_chunks (
bool, optional): Passed to the underlying read path. Defaults toFalse.
Returns
- dict: A htype-specific dictionary.
Return Format
text,json,list, andtagtensors return{"value": ...}usingTensor.text(),Tensor.dict(), orTensor.list().videotensors return{"frames": ..., "timestamps": ..., "sample_info": ...}.class_labeltensors return{"value": ...}and, when class names are configured,"text".image,image.rgb,image.gray,dicom, andniftitensors return{"value": ..., "sample_info": ...}.- Other htypes return
{"value": ...}using numpy-backed data.
Example
value = ds.labels[0].data()["value"]
image = ds.images[0].data()
Tensor.text()
Signature
Tensor.text(fetch_chunks=False)
Parameters
- fetch_chunks (
bool, optional): Passed to the underlying numpy read. Defaults toFalse.
Returns
- Any: Text value for one selected sample, or a list of text values for multiple selected samples.
Raises
- Exception: If the tensor base htype is not
text.
Example
caption = ds.captions[0].text()
captions = ds.captions[:3].text()
Tensor.dict()
Signature
Tensor.dict(fetch_chunks=False)
Parameters
- fetch_chunks (
bool, optional): Passed to the underlying numpy read. Defaults toFalse.
Returns
- Any: JSON value for one selected sample, or a list of JSON values for multiple selected samples.
Raises
- Exception: If the tensor base htype is not
json.
Example
metadata = ds.metadata[0].dict()
Tensor.list()
Signature
Tensor.list(fetch_chunks=False)
Parameters
- fetch_chunks (
bool, optional): Passed to the underlying numpy read. Defaults toFalse.
Returns
- list: List data for tensors with base htype
listortag.
Raises
- Exception: If the tensor base htype is not
listortag.
Example
tags = ds.tags[0].list()
Tensor.tobytes()
Signature
Tensor.tobytes()
Parameters
None.
Returns
- bytes: Raw bytes for exactly one selected sample. For uncompressed tensors this is the numpy-array bytes; for sample-compressed tensors this is the compressed sample bytes.
Raises
- ValueError: If the tensor view selects zero, multiple, or sliced samples.
Example
raw = ds.images[0].tobytes()
Index Access
Signature
tensor[item]
Parameters
- item (
int,np.integer,slice,list,tuple,Ellipsis, orIndex): Index expression used to create a tensor view.
Returns
- Tensor: A lazy tensor view over the selected samples or dimensions. Data is loaded only when a read method such as
numpy(),data(), ortobytes()is called.
Raises
- InvalidKeyTypeError: If the index type is unsupported.
Example
one_sample = ds.images[0]
batch = ds.images[10:20]
array = batch.numpy(aslist=True)
Properties
Tensor.htype
Type
- str
Description
High-level tensor type, such as generic, image, text, json, list, class_label, or vector. This property can be assigned for supported htype conversions; unsupported conversions raise an error.
Tensor.dtype
Type
- np.dtype or None
Description
Numpy dtype for the tensor. For base htypes json, list, and tag, this returns np.dtype(str). If dtype metadata is unavailable, it returns None.
Tensor.shape
Type
- Tuple[Optional[int], ...]
Description
Shape of the current tensor view. Dynamic dimensions are represented with None.
Tensor.shape_interval
Type
- ShapeInterval
Description
Minimum and maximum shape information for the current tensor view. Use this to inspect whether samples have dynamic shapes.
Tensor.ndim
Type
- int
Description
Number of dimensions in the current tensor view.
Tensor.num_samples
Type
- int
Description
Total number of samples in the tensor. This ignores the current tensor view index and returns the length of the primary axis for the full tensor.
Tensor.sample_info
Type
- dict, List[dict], or None
Description
Sample metadata for the current tensor view. A single-sample view returns a dict, a multi-sample view returns a list of dicts, and tensors without a sample-info tensor return None.
Sample info is available only when the dataset was created with the corresponding hidden sample-info tensor, for example by passing create_sample_info_tensor=True to create_tensor() for supported media htypes.