File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -37,10 +37,11 @@ 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
40
+ if not isinstance (X , np .ndarray ):
41
+ raise ValueError ("Input must be a numpy array" )
42
+ if X .ndim != 2 :
43
+ raise ValueError ("Input array must be 2D" )
44
+ i , j = np .unravel_index (np .argmax (X ), X .shape )
44
45
45
46
return i , j
46
47
@@ -64,4 +65,10 @@ def wallis_product(n_terms):
64
65
"""
65
66
# XXX : The n_terms is an int that corresponds to the number of
66
67
# terms in the product. For example 10000.
67
- return 0.
68
+ if not isinstance (n_terms , int ) or n_terms < 0 :
69
+ raise ValueError ("n_terms must be a non negative integer" )
70
+
71
+ approx = 1.
72
+ for i in range (1 , n_terms + 1 ):
73
+ approx *= (4 * i ** 2 ) / (4 * i ** 2 - 1 )
74
+ return approx * 2
You can’t perform that action at this time.
0 commit comments