python - How to convert a list in a float? -


my code has following error: float () argument must string or number, not 'list'.

i know ww function list of values, not know how convert float, since ww function. tried list comprehension, following question in:

typeerror: float() argument must string or number, not 'list' python

but didn't work.

def func(n):     return 2/(n+1)  def ww(n):     return [-1 + i*func(n) in range(0,n+1)]   def g(x,y):     return x**2 + y 

this g(x,y) spherical harmonics, put simplicity.

def integral(n):     return [np.pi*func(n)*(1 + math.cos(np.pi*(-1 + i*func(n))))*g(np.pi*i,ww(n)) in range(0,n+1)]    

your ww function returns list of floats, passed g(). calculation fails because cannot add list number.

it not possible "convert list of floats float" without performing sort of operation on numbers — e.g. "add", "subtract", "multiply".

however, can convert list numpy array, can operated on whole. multiplying array of numbers single number multiplies each value, returning result.

for example:

>>> = np.array([1.0,2.0,3.0]) >>> b = 2 >>> b ** 2 + array([5.0, 6.0, 7.0]) 

if wrap return value of ww convert numpy array, subsequent calculation in g() should work.

def ww(n):     return np.array([-1 + i*func(n) in range(0,n+1)]) 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -