lambdified 函数的doc 显示实际上是numpy 代码。有时看看这个会有所帮助。
破译您的png 需要一些时间(我们通常不喜欢 SO 上的那些)。我猜这是result 数组的pydev 显示。它看起来像一个形状 (8,) 对象 dtype 数组。大部分元素是 shape(33,) 数组,但最后 2 个是标量。
np.stack(result[:6])
应该产生一个 (8,33) 数字 dtype 数组。
对象 dtype 数组很像一个列表,其中包含对不同元素的引用。
看看你的多项式,我猜lambdified函数返回如下内容:
np.array([7*t**6, ..., 2*t, 1, 0])
虽然其中 6 个术语包含 t,但最后 2 个不包含。包含t 的术语将生成一个 (33,) 数组。 sympy.lambdify 是一个相对简单的函数,执行从sympy 到numpy 的词法转换。它对numpy没有“深入”的了解。
例子:
In [25]: exp = (3*t**3,2*t**2,1*t,1.0,0)
In [26]: f = lambdify(t, exp)
In [27]: print(f.__doc__)
Created with lambdify. Signature:
func(t)
Expression:
(3*t**3, 2*t**2, t, 1.0, 0)
Source code:
def _lambdifygenerated(t):
return ((3*t**3, 2*t**2, t, 1.0, 0))
In [28]: f(np.arange(3))
Out[28]: (array([ 0, 3, 24]), array([0, 2, 8]), array([0, 1, 2]), 1.0, 0)
In [29]: np.array(_)
<ipython-input-29-7a2cd91c32ca>:1: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
np.array(_)
Out[29]:
array([array([ 0, 3, 24]), array([0, 2, 8]), array([0, 1, 2]), 1.0, 0],
dtype=object)