Skip to content

Commit 494953a

Browse files
committed
Completed assignment
1 parent d31f7ef commit 494953a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

numpy_questions.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def max_index(X):
4040
i = 0
4141
j = 0
4242

43-
# TODO
43+
if not isinstance(X, np.ndarray) or X.ndim != 2:
44+
raise ValueError("Input must be a 2D numpy array.")
45+
flat_index = np.argmax(X)
46+
i, j = np.unravel_index(flat_index, X.shape)
4447

4548
return i, j
4649

@@ -64,4 +67,8 @@ def wallis_product(n_terms):
6467
"""
6568
# XXX : The n_terms is an int that corresponds to the number of
6669
# terms in the product. For example 10000.
67-
return 0.
70+
product = 1.0
71+
for k in range(1, n_terms + 1):
72+
product *= (4 * k**2) / (4 * k**2 - 1)
73+
pi = 2 * product
74+
return pi

0 commit comments

Comments
 (0)