Skip to content

Commit 3323ed3

Browse files
committed
Implemented two functions
1 parent d31f7ef commit 3323ed3

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

numpy_questions.py

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

43-
# TODO
43+
if not isinstance(X, np.ndarray):
44+
raise ValueError('Work with Numpy array only')
45+
46+
if not X.ndim == 2:
47+
raise ValueError('Work with 2D arrays only')
48+
49+
max_index = np.argmax(X)
50+
i, j = np.unravel_index(max_index, X.shape)
4451

4552
return i, j
4653

@@ -64,4 +71,11 @@ def wallis_product(n_terms):
6471
"""
6572
# XXX : The n_terms is an int that corresponds to the number of
6673
# terms in the product. For example 10000.
67-
return 0.
74+
product = 1.0
75+
76+
for n in range(1, n_terms + 1):
77+
term = (4 * n**2) / (4 * n**2 - 1)
78+
product *= term
79+
80+
pi_approx = 2 * product
81+
return pi_approx

0 commit comments

Comments
 (0)