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.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

3

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])

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest