File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -37,11 +37,17 @@ def max_index(X):
37
37
If the input is not a numpy array or
38
38
if the shape is not 2D.
39
39
"""
40
- i = 0
41
- j = 0
42
-
43
- # TODO
44
-
40
+
41
+ if not isinstance (X , np .ndarray ):
42
+ raise ValueError ("Input must be a numpy array." )
43
+
44
+ if X .ndim != 2 :
45
+ raise ValueError ("Input must be a 2D numpy array." )
46
+
47
+ if X .size == 0 :
48
+ raise ValueError ("Input array must not be empty." )
49
+
50
+ i , j = np .unravel_index (np .argmax (X ), X .shape )
45
51
return i , j
46
52
47
53
@@ -62,6 +68,7 @@ def wallis_product(n_terms):
62
68
pi : float
63
69
The approximation of order `n_terms` of pi using the Wallis product.
64
70
"""
65
- # XXX : The n_terms is an int that corresponds to the number of
66
- # terms in the product. For example 10000.
67
- return 0.
71
+ pi = 1
72
+ for i in range (1 , n_terms + 1 ):
73
+ pi *= (4 * i ** 2 ) / (4 * i ** 2 - 1 )
74
+ return 2 * pi
You can’t perform that action at this time.
0 commit comments