Я пишу функцию на Python product_z
, которая вычисляет произведение (N ^ z) / z * ∏ k / z + k от k = 1 до N.
Код выглядит следующим образомthis;
import numpy as np
def z_product(z,N):
terms = [k/(z+k) for k in range(1,N+1)]
total = (N^z/z)*np.prod(terms)
return total
Тем не менее, я, например, запускаю код с этим вводом, но я получаю в ответ TypeError.
"Check that z_product returns the correct datatype."
assert type(z_product(2,7)) == np.float64 , "Return value should be a NumPy float."
print("Problem 2 Test 1: Success!")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-9-d2e9161f328a> in <module>()
1 "Check that z_product returns the correct datatype."
----> 2 assert type(z_product(2,7)) == np.float64 , "Return value should be
a NumPy float."
3 print("Problem 2 Test 1: Success!")
<ipython-input-8-1cd27b06388f> in z_product(z, N)
1 def z_product(z,N):
2 terms = [k/(z+k) for k in range(1,N+1)]
----> 3 total = (N^z/z)*np.prod(terms)
4 return total
TypeError: unsupported operand type(s) for ^: 'int' and 'float'
Что я делаю не так и как я могу это исправить, чтобы заставить код работать?