【发布时间】:2021-12-04 14:20:11
【问题描述】:
我的 python 代码有一些问题,我正在使用 sympy 并想创建一个 Lambda 函数,该函数将实数列表 [a1,a2,...,an] 作为输入并返回一个列表实数 [b1,b2,...,bn] 其中 bi=cos(ai) +sin(ai)。 iε[1, 2, ..., n] 但是,我遇到了一个属性错误,即
AttributeError: 'list' object has no attribute 'is_Number'
这是我的代码(我很新,知道这不是最好的):
import sympy
# defining symbol 'x'
x = sympy.symbols('x')
# defining a lambda function that takes a list of values and returns the
# result of applying the formula cos(x)+sin(x) for each input value provided
f = sympy.Lambda(x, sympy.cos(x) + sympy.sin(x))
# testing by creating a list
input_list = [-1, -0.5, 0, 0.5, 1]
# calling f method to fetch the results of applying cos()+sin() for each value in input_list
output_list = f(input_list)
# printing both lists
print(input_list)
print(output_list)
【问题讨论】:
标签: python list sympy attributeerror