Typeerror: Must Be Real Number, Not List
I Am Trying to Get the Cosine Inverse of a Number. but It Is Showing an Error Message for I in S: Nr=[((I[0]*P)+(I[1]*Q))/(Math. Sqrt(I[0]**2+I[1]**2)*Math...
I am trying to get the cosine inverse of a number. But it is showing an error message
for i in S:
nr=[((i[0]*p)+(i[1]*q))/(math.sqrt(i[0]**2+i[1]**2)*math.sqrt(p**2+q**2)) for (p,q) in P]
print(nr)
dist=math.acos(nr)
The last statement is throwing an error "must be real number, not list" However, nr is not a list. I am not sure what is the error
Request help in understanding this. Thanks in advance
1 Answer
nr=[((i[0]*p)+(i[1]*q))/(math.sqrt(i[0]**2+i[1]**2)*math.sqrt(p**2+q**2)) for (p,q) in P]
This, is a list comprehension, meaning that nr is a list. It's complaining because you can't do acos of a list.
As you said in your comment, P is a single element list, so your nr list contains only one element, but it's still a list. Try doing math.acos(nr[0])