我有以下代码:
import numpy as np
import math
x = np.arange(0, 1.1, h) #point in space
t = np.arange(0, 1.1, k) #point in time
#nodes in matrix form
m = len(x)
n = len(t)
T = np.zeros((m,n))
def ft0 (x):
f = lambda x: math.sin(math.pi*x)# Initial Condition at t=0
return f
for i in range (m-1):
T[0][i] = ft0[i]
当我运行代码时,我得到:
TypeError: float() argument must be a string or a number, not 'function'
我一直在网上寻找解决方案,但我并不真正理解错误
代码中存在多个问题
h
,k
没有在您提供的代码中定义,我假设它们都是0.1ft0(i)
,而不是像您那样李>lambda
函数而不是结果,因此应将其更改为...return f(x)
而不是...return f
,这会导致上述错误李>您可以在以下代码中看到上述内容:
注意
column
,可能应该使用double for循环lambda
的情况下,像您所做的那样是不必要的,您可以将lambda
用作函数。我建议您在下面的链接https://realpython.com/python-lambda/中阅读有关它的内容相关问题 更多 >
编程相关推荐