File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,16 @@ def max_index(X):
40
40
i = 0
41
41
j = 0
42
42
43
- # TODO
43
+ # Validate input is a numpy array
44
+ if not isinstance (X , np .ndarray ):
45
+ raise ValueError ("Input must be a numpy array." )
46
+ # Validate input shape
47
+ if X .ndim != 2 :
48
+ raise ValueError ("Input array must be 2-dimensional." )
49
+
50
+ # Find the row and columnd index of the maximum
51
+ max_value = np .max (X )
52
+ i , j = np .where (X == max_value )
44
53
45
54
return i , j
46
55
@@ -62,6 +71,12 @@ def wallis_product(n_terms):
62
71
pi : float
63
72
The approximation of order `n_terms` of pi using the Wallis product.
64
73
"""
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.
74
+ pi = 1
75
+
76
+ if n_terms < 0 :
77
+ raise ValueError ("n_terms must be a positive integer." )
78
+ if n_terms > 0 :
79
+ for i in range (1 , n_terms + 1 ):
80
+ pi *= (4 * i ** 2 ) / (4 * i ** 2 - 1 )
81
+
82
+ return pi * 2
You can’t perform that action at this time.
0 commit comments