We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d31f7ef commit 8e81aabCopy full SHA for 8e81aab
numpy_questions.py
@@ -40,7 +40,13 @@ def max_index(X):
40
i = 0
41
j = 0
42
43
- # TODO
+ if not isinstance(X, np.ndarray):
44
+ raise ValueError("Input must be a numpy array.")
45
+
46
+ if X.ndim != 2:
47
+ raise ValueError("Input array must be 2D.")
48
49
+ i, j = np.unravel_index(np.argmax(X), X.shape)
50
51
return i, j
52
@@ -64,4 +70,12 @@ def wallis_product(n_terms):
64
70
"""
65
71
# XXX : The n_terms is an int that corresponds to the number of
66
72
# terms in the product. For example 10000.
67
- return 0.
73
+ if n_terms < 0:
74
+ raise ValueError("Number of terms must be non-negative.")
75
76
+ product = 2.0
77
78
+ for i in range(1, n_terms + 1):
79
+ product *= (4 * i ** 2) / (4 * i ** 2 - 1)
80
81
+ return product
0 commit comments