Skip to content

Commit b2022a5

Browse files
committed
Up my solution
1 parent d31f7ef commit b2022a5

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

numpy_questions.py

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

43-
# TODO
44-
43+
if not isinstance(X, np.ndarray):
44+
raise ValueError("The input should be a numpy array.")
45+
if len(X.shape) != 2:
46+
raise ValueError("The input should be a 2D numpy array.")
47+
i, j = np.unravel_index(np.argmax(X), X.shape)
4548
return i, j
4649

4750

@@ -64,4 +67,12 @@ 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+
71+
if not isinstance(n_terms, int):
72+
raise ValueError("The input should be an integer.")
73+
if n_terms < 0:
74+
raise ValueError("The input should be a positive integer.")
75+
pi = 1
76+
for i in range(1, n_terms+1):
77+
pi *= (4*i**2)/(4*i**2 - 1)
78+
return 2*pi

0 commit comments

Comments
 (0)