Skip to content

Commit 5eb1345

Browse files
Pauline ZhouPauline Zhou
Pauline Zhou
authored and
Pauline Zhou
committed
numpy Test passed
1 parent d31f7ef commit 5eb1345

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

numpy_questions.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,24 @@ def max_index(X):
4141
j = 0
4242

4343
# TODO
44+
if isinstance(X, np.ndarray) == False:
45+
raise ValueError("The input is not a numpy array")
46+
47+
elif X.ndim != 2:
48+
raise ValueError("The shape is not 2D")
49+
50+
else:
51+
for row in range(X.shape[0]):
52+
for col in range(X.shape[1]):
53+
if X[row, col] > X[i, j]:
54+
i = row
55+
j = col
4456

4557
return i, j
4658

59+
# X = np.array([[1,2],[3,4]])
60+
# print("X", max_index(X))
61+
4762

4863
def wallis_product(n_terms):
4964
"""Implement the Wallis product to compute an approximation of pi.
@@ -64,4 +79,5 @@ def wallis_product(n_terms):
6479
"""
6580
# XXX : The n_terms is an int that corresponds to the number of
6681
# terms in the product. For example 10000.
67-
return 0.
82+
83+
return 2 * np.prod([(4 * i**2) / (4 * i**2 - 1) for i in range(1, n_terms + 1)])

0 commit comments

Comments
 (0)