EigenPy

3.12.0 · active · verified Mon Apr 13

EigenPy provides seamless Python bindings between NumPy arrays and Eigen C++ dense matrix types, utilizing Boost.Python. It allows for efficient data exchange and manipulation, exposing Eigen types and operations directly to Python. The current version is 3.12.0, with a release cadence that tends to follow updates in underlying dependencies or related projects like Pinocchio and Crocoddyl.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core functionality of EigenPy: enabling the bindings, creating an Eigen matrix, converting it to a NumPy array (showing view semantics), and converting a NumPy array back to an Eigen matrix (showing copy semantics).

import eigenpy
import numpy as np

# IMPORTANT: Enable EigenPy functionality
eigenpy.enableEigenPy()

# Create an Eigen MatrixXd instance (from C++ bindings)
mat_eigen = eigenpy.MatrixXd(3, 3)
mat_eigen.setRandom()
print('Eigen MatrixXd (random):\n', mat_eigen)

# Convert Eigen matrix to NumPy array (creates a view by default)
np_view = np.asarray(mat_eigen)
print('\nNumPy view of Eigen matrix:\n', np_view)

# Modifying the NumPy view also modifies the underlying Eigen matrix
np_view[0, 0] = 99.0
print('\nEigen MatrixXd after NumPy view modification:\n', mat_eigen)

# Convert NumPy array to Eigen matrix (creates a copy by default)
numpy_orig = np.array([[1.0, 2.0], [3.0, 4.0]])
mat_eigen_from_np = eigenpy.toEigen(numpy_orig)
print('\nEigen matrix from NumPy array:\n', mat_eigen_from_np)

view raw JSON →