Skip to content

Support for 3D lookup table? #3648

Answered by b-mare
yuxng asked this question in Q&A
Mar 30, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @yuxng ,

The documentation mentions it is possible for an arbitrary number of dimensions.
https://web.casadi.org/docs/#using-lookup-tables

Example

import numpy as np
import casadi as ca
from scipy.interpolate import RegularGridInterpolator

xgrid = np.linspace(0, 4, 3)
ygrid = np.linspace(10, 16, 4)
zgrid = np.linspace(20, 30, 5)
X, Y, Z = np.meshgrid(xgrid, ygrid, zgrid, indexing="ij")
data = 2 * X + Y / Z
data_flat = data.ravel(order="F")
lut = ca.interpolant("lut", "linear", [xgrid, ygrid, zgrid], data_flat)
interp_func = RegularGridInterpolator((xgrid, ygrid, zgrid), data, method='linear')

print(lut([2, 12, 27.5]))
print(interp_func([2, 12, 27.5]))

4.43636
[4.43636364]

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yuxng
Comment options

Answer selected by yuxng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants