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 494953aCopy full SHA for 494953a
numpy_questions.py
@@ -40,7 +40,10 @@ def max_index(X):
40
i = 0
41
j = 0
42
43
- # TODO
+ if not isinstance(X, np.ndarray) or X.ndim != 2:
44
+ raise ValueError("Input must be a 2D numpy array.")
45
+ flat_index = np.argmax(X)
46
+ i, j = np.unravel_index(flat_index, X.shape)
47
48
return i, j
49
@@ -64,4 +67,8 @@ def wallis_product(n_terms):
64
67
"""
65
68
# XXX : The n_terms is an int that corresponds to the number of
66
69
# terms in the product. For example 10000.
- return 0.
70
+ product = 1.0
71
+ for k in range(1, n_terms + 1):
72
+ product *= (4 * k**2) / (4 * k**2 - 1)
73
+ pi = 2 * product
74
+ return pi
0 commit comments