For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
numpy
NumPy interoperability helpers for Mojo collections.
These functions move flat numeric data between Mojo Span and NumPy
arrays when a Mojo program drives CPython (via Python.import_module), without
hand-written ctypes plumbing:
to_numpy_arraybuilds a NumPy array from a MojoSpanby copying the data into a new, independent array.from_numpy_arrayborrows a NumPy array's buffer as a MojoSpan(zero-copy).
Only 1-D, C-contiguous arrays of the fixed-width numeric dtypes (int8 through
int64, uint8 through uint64, float16, float32, float64) are
supported. This targets the common case of handing computed numeric data to a
library such as matplotlib.
Functions
-
from_numpy_array: Borrows a 1-D C-contiguous NumPy array as a MojoSpan. -
to_numpy_array: Builds a 1-D NumPy array from a MojoSpanof scalars.