File tree 1 file changed +21
-4
lines changed
1 file changed +21
-4
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
40
+ # Test if the input is a numpy array or not
41
+ if not isinstance (X , np .ndarray ):
42
+ raise ValueError ("Input is not a numpy array." )
42
43
43
- # TODO
44
+ # Test if the input is in 2D
45
+ if X .ndim != 2 :
46
+ raise ValueError ("Input array is not in 2D." )
44
47
48
+ # Return the index tupple corresponding
49
+ # to the maximum in the input numpy array
50
+ i , j = np .unravel_index (np .argmax (X ), X .shape )
45
51
return i , j
46
52
47
53
@@ -64,4 +70,15 @@ 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
+ product = 1.0
74
+ if n_terms == 0 :
75
+ return product * 2
76
+
77
+ for n in range (1 , n_terms + 1 ):
78
+ numerator = 4 * n ** 2
79
+ denominator = numerator - 1
80
+ product *= numerator / denominator
81
+
82
+ pi_approx = 2 * product
83
+
84
+ return pi_approx
You can’t perform that action at this time.
0 commit comments