Skip to content

Commit 2e0dff8

Browse files
UP my solution
1 parent d31f7ef commit 2e0dff8

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

numpy_questions.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ def max_index(X):
4141
j = 0
4242

4343
# TODO
44+
if not isinstance(X, np.ndarray):
45+
raise ValueError("Input must be a NumPy array.")
46+
47+
if X.ndim != 2:
48+
raise ValueError("Input array must be 2-dimensional.")
49+
50+
max_value = X[i, j]
51+
52+
for x in range(X.shape[0]):
53+
for y in range(X.shape[1]):
54+
if X[x, y] > max_value:
55+
max_value = X[x, y]
56+
i, j = x, y
4457

4558
return i, j
4659

@@ -64,4 +77,16 @@ def wallis_product(n_terms):
6477
"""
6578
# XXX : The n_terms is an int that corresponds to the number of
6679
# terms in the product. For example 10000.
67-
return 0.
80+
81+
if n_terms < 0:
82+
raise ValueError("n_term cannot be negative")
83+
84+
product = 1
85+
86+
if n_terms == 0:
87+
return product*2
88+
89+
for i in range(1, n_terms + 1):
90+
product *= (4 * i**2) / (4 * i**2 - 1)
91+
92+
return product*2

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ numpy
22
scipy
33
scikit-learn
44
pandas
5+
pytest
6+
flake8

0 commit comments

Comments
 (0)