IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
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_array builds a NumPy array from a Mojo Span by copying the data into a new, independent array.
  • from_numpy_array borrows a NumPy array's buffer as a Mojo Span (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