File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,13 @@ def max_index(X):
41
41
j = 0
42
42
43
43
# TODO
44
+ if not isinstance (X , np .ndarray ):
45
+ raise ValueError ("Input must be a numpy array." )
46
+ if X .ndim != 2 :
47
+ raise ValueError ("Input must be a 2D array." )
44
48
49
+ max_idx = np .unravel_index (np .argmax (X ), X .shape )
50
+ i , j = max_idx
45
51
return i , j
46
52
47
53
@@ -64,4 +70,12 @@ 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
+ if n_terms < 0 :
74
+ raise ValueError ("Number of terms must be non-negative." )
75
+
76
+ product = 1.0
77
+ for n in range (1 , n_terms + 1 ):
78
+ term = (4 * n ** 2 ) / (4 * n ** 2 - 1 )
79
+ product *= term
80
+
81
+ return product * 2
You can’t perform that action at this time.
0 commit comments