File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,14 @@ def max_index(X):
40
40
i = 0
41
41
j = 0
42
42
43
- # TODO
43
+ if not isinstance (X , np .ndarray ):
44
+ raise ValueError ("Input must be a numpy array." )
45
+
46
+ if X .ndim != 2 :
47
+ raise ValueError ("Input array must be 2-dimensional." )
48
+
49
+ max_idx = np .unravel_index (np .argmax (X ), X .shape )
50
+ i , j = max_idx
44
51
45
52
return i , j
46
53
@@ -62,6 +69,11 @@ def wallis_product(n_terms):
62
69
pi : float
63
70
The approximation of order `n_terms` of pi using the Wallis product.
64
71
"""
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.
72
+ product = 1.0
73
+
74
+ for n in range (1 , n_terms + 1 ):
75
+ product *= (4 * n ** 2 ) / ((4 * n ** 2 ) - 1 )
76
+
77
+ pi = product * 2
78
+
79
+ return pi
You can’t perform that action at this time.
0 commit comments