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 3323ed3Copy full SHA for 3323ed3
numpy_questions.py
@@ -40,7 +40,14 @@ def max_index(X):
40
i = 0
41
j = 0
42
43
- # TODO
+ if not isinstance(X, np.ndarray):
44
+ raise ValueError('Work with Numpy array only')
45
+
46
+ if not X.ndim == 2:
47
+ raise ValueError('Work with 2D arrays only')
48
49
+ max_index = np.argmax(X)
50
+ i, j = np.unravel_index(max_index, X.shape)
51
52
return i, j
53
@@ -64,4 +71,11 @@ def wallis_product(n_terms):
64
71
"""
65
72
# XXX : The n_terms is an int that corresponds to the number of
66
73
# terms in the product. For example 10000.
67
- return 0.
74
+ product = 1.0
75
76
+ for n in range(1, n_terms + 1):
77
+ term = (4 * n**2) / (4 * n**2 - 1)
78
+ product *= term
79
80
+ pi_approx = 2 * product
81
+ return pi_approx
0 commit comments