fields.buffers.core.UnytArrayBuffer.from_array#

classmethod UnytArrayBuffer.from_array(obj: Any, dtype: Any | None = None, units: Unit | str | None = None, *args, registry: UnitRegistry | None = None, bypass_validation: bool = False, name: str | None = None, **kwargs) UnytArrayBuffer[source]#

Construct a new unit-aware buffer from any array-like input.

This method wraps the input in an unyt_array, preserving or applying physical units as needed. It handles input that is already a unyt_array or unyt_quantity, a plain numpy.ndarray, or any array-like object (e.g., list, tuple) that can be converted via numpy.array().

Parameters:
  • obj (array-like) – The input data to interpret as a buffer. Regardless of the input type, the data will be coerced to a unyt_array and then wrapped in UnytArrayBuffer.

  • units (str or Unit, optional) – Physical units to attach to the resulting array. If not provided and obj has attached units, they are preserved. Otherwise defaults to dimensionless.

  • dtype (data-type, optional) – Desired data type of the resulting array. If not specified, inferred from input.

  • registry (UnitRegistry, optional) – Registry to associate with the units, if applicable.

  • bypass_validation (bool, default False) – If True, skip unit and value validation (faster but unsafe for malformed input).

  • name (str, optional) – Optional name for the array (useful for annotation).

  • **kwargs – Additional keyword arguments passed to numpy.array() if the input must be coerced.

Returns:

A buffer instance wrapping the resulting unyt_array.

Return type:

UnytArrayBuffer

Raises:

TypeError – If the input cannot be converted into a unyt_array.

Notes

Input Type Behavior: