Skip to content

Commit de39402

Browse files
committed
Update numpy_questions.py
1 parent a90bda9 commit de39402

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

numpy_questions.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def max_index(X):
4646
raise ValueError("Input is not a 2D array")
4747
i, j = np.unravel_index(np.argmax(X), X.shape)
4848
return i, j
49-
49+
5050

5151

5252
def wallis_product(n_terms):
@@ -68,4 +68,13 @@ def wallis_product(n_terms):
6868
"""
6969
# XXX : The n_terms is an int that corresponds to the number of
7070
# terms in the product. For example 10000.
71-
return 0.
71+
72+
if n_terms < 0:
73+
raise ValueError("n_terms should be a positive integer")
74+
if n_terms == 0:
75+
return 1.
76+
77+
pi = 1.
78+
for i in range(1, n_terms+1):
79+
pi *= 4*i**2/(4*i**2-1)
80+
return 2*pi

0 commit comments

Comments
 (0)