Giter Site home page Giter Site logo

Printing matrices in casadi about biorbd HOT 2 CLOSED

yugiero avatar yugiero commented on August 29, 2024
Printing matrices in casadi

from biorbd.

Comments (2)

pariterre avatar pariterre commented on August 29, 2024

Hi there!
Casadi does not actually carry actual data, but graph of the code that can generate the results of a computation. Therefore, it is sort of meaningless to get the array, as MX are graphs. Henceforth, there is no such thing as to_array(), but you can get the graph using to_mx().

That said, you can evaluate the graph. You must, however, first convert the graph (the MX) to a casadi.Function and then you can call that very function to evaluate the graph. I made an easy interface to convert to casadi.Function in Python. It would look something like:

import biorbd_casadi as casadi
from casadi import MX
import numpy as np

# Get a model
model = biorbd.Model("pendulum.bioMod")

# Create a symbolic variable of dimension (nq x 1) that will be used to create the graph
q_symbolic = MX.sym("q", model.nbQ(), 1) 

# Create the casadi function
com_func = biorbd.to_casadi_func('com', model.CoM, q_symbolic)  # Alternatively you can create yourself the function using casadi.Function

# Evaluate the graph with actual data
q = np.random.rand(model.nbQ())  # This can also be casadi.DM
com = com_func(q)  # This a DM, but can be converted to array using "com = np.array(com)"
print(com)

Hope this helps!

from biorbd.

yugiero avatar yugiero commented on August 29, 2024

Interesting, thanks a lot!

from biorbd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.