Skip to main content

wt::python

wt::python

Functions

Name
template <typename T >
py::array_t< T >
span_to_numpy_readonly(std::span< T const > data, py::handle owner)
Create a read-only NumPy array that views a C++ span (zero-copy).
template <typename T >
std::vector< T >
numpy_to_vector(py::array_t< T, py::array::c_style

Functions Documentation

function span_to_numpy_readonly

template <typename T >
py::array_t< T > span_to_numpy_readonly(
    std::span< T const > data,
    py::handle owner
)

Create a read-only NumPy array that views a C++ span (zero-copy).

Parameters:

  • data Contiguous span of const data.
  • owner A Python handle whose ref-count keeps the underlying C++ memory alive. Typically py::cast(shared_ptr).

Template Parameters:

  • T Element type (float, double, int64_t, …).

Return: A 1-D NumPy array with the WRITEABLE flag cleared.

function numpy_to_vector

template <typename T >
std::vector< T > numpy_to_vector(
    py::array_t< T, py::array::c_style|py::array::forcecast > arr
)

Copy a NumPy array into a std::vector.


Updated on 2026-11-13 at 20:25:41 +0000