Answer the question
In order to leave comments, you need to log in
Why doesn't the formula work?
There is such a formula:
Using this formula, I try to calculate my values using the numpy library:
I got the following code:
N = np.arange(proc+1)
np.sum(np.power(R, N) / (math.factorial(N)))
TypeError: only size-1 arrays can be converted to Python scalars
Answer the question
In order to leave comments, you need to log in
To apply factorial to arrays, you need to vectorize the function:
>>> import numpy as np
>>> np.math.factorial(np.arange(6))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: only size-1 arrays can be converted to Python scalars
>>> factorial = np.vectorize(np.math.factorial)
>>> factorial(np.arange(6))
array([ 1, 1, 2, 6, 24, 120])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question