The problem is using star imports instead of importing each package under a different namespace.
This imports function sympy.functions.elementary.trigonometric.cos
under the cos
name:
from sympy import *
After that, you import <ufunc 'cos'>
under the name cos
, overwriting the previous definition:
from scipy import *
Then, it overwrites the previous cos
function by another copy of exactly the same function (from the matplotlib package):
from pylab import *
This also imports the same <ufunc 'cos'>
but under the np.cos
name. This is the proper way to import things:
import numpy as np
In the end, you're left with a copy of the cos function that knows how to apply itself to floats, not sympy objects. When you try to apply that function to sympy objects like phi
you get the AttributeError
. All in all, the solution to this particular problem is to fix the imports and know if you want the functions from sympy or the ones from numpy.