Python Error ‘list’ object has no attribute ‘is_Number’ Code Answer

I am having some issues with my python code, I am using sympy and would like to create a Lambda function that takes as input a list of real numbers [a1,a2,…,an] and return a list of real numbers [b1,b2,…,bn] where bi=cos(ai) +sin(ai). iε[1, 2, …, n] I am running into an attribute error, however, which is

AttributeError: 'list' object has no attribute 'is_Number'

Here is my code (I am quite new and know it is not the best):

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


In your case f doesn’t take a list but just a value x, so in order to get your output, you need to do this…

output_list = [sympy.N(f(x)) for x in input_list]

This will output following for your input

[-0.301168678939757, 0.398157023286170, 1.00000000000000, 1.35700810049458, 1.38177329067604]

Related Posts

© No Copyrights, All Questions are retrived from public domain.
Tutorial Guruji