-
Notifications
You must be signed in to change notification settings - Fork 67
Open
Description
I don't know if this is intentional, but using lambdify with symengine
on a 2d symbolic ndarray or matrix creates a function that does not return a 2d ndarray. Instead, it returns a list of ndarrays.
Even stranger, when using a Matrix
, the return value is a flat list of ndarrays, which is not the same as the converted symbolic numpy array.
When using lambdify from sympy
on a matrix, a function with a pure 2d ndarray is returned.
import sympy as sp
import symengine as se
import numpy as np
x = se.Symbol("x")
A = np.array([
[x, x+1],
[x+2, x+3]
])
f = se.lambdify(x, A)
y = f(1.0)
print(type(y), y)
# <class 'list'>
# [array([1., 2.]), array([3., 4.])]
A = se.Matrix(2, 2, [
[x, x+1],
[x+2, x+3]
])
f = se.lambdify(x, A)
y = f(1.0)
print(type(y), y)
# <class 'list'>
# [array(1.), array(2.), array(3.), array(4.)]
x = sp.Symbol("x")
A = sp.Matrix([
[x, x+1],
[x+2, x+3]
])
f = sp.lambdify(x, A)
y = f(1.0)
print(type(y), y)
# <class 'numpy.ndarray'>
# [[1. 2.]
# [3. 4.]]
The current workaround is to convert the list of arrays into a 2d ndarray.
bjodah
Metadata
Metadata
Assignees
Labels
No labels