fields.buffers.core.ArrayBuffer.from_array#

classmethod ArrayBuffer.from_array(obj: Any, *args, dtype: Any | None = None, **kwargs) ArrayBuffer[source]#

Construct a new ArrayBuffer from an arbitrary array-like input.

This method attempts to coerce the input into a valid numpy.ndarray and wrap it in an ArrayBuffer instance. It serves as the standard mechanism for converting raw or structured numerical data (e.g., lists, tuples, or other array-compatible types) into a compatible buffer for numerical operations.

This constructor mimics the behavior of numpy.array() and accepts keyword arguments like dtype, order, and copy to control how the data is materialized. Subclasses may override this method to enforce stricter requirements or attach additional metadata.

Parameters:
  • obj (array-like) – Input data to be wrapped. This can include Python lists, tuples, NumPy arrays, or other objects that support array conversion via numpy.array().

  • dtype (data-type, optional) – Desired data type for the resulting array. If omitted, the data type is inferred from obj.

  • *args – Additional keyword arguments passed to numpy.array() to control coercion behavior (e.g., copy, order, etc.).

  • **kwargs – Additional keyword arguments passed to numpy.array() to control coercion behavior (e.g., copy, order, etc.).

Returns:

A buffer instance wrapping the resulting numpy.ndarray.

Return type:

ArrayBuffer

Raises:

TypeError – If the input cannot be coerced into a NumPy array.