File tree 1 file changed +22
-6
lines changed
1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -37,12 +37,22 @@ 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
40
43
- # TODO
41
+ if not isinstance (X , np .ndarray ):
42
+ raise ValueError ("the input is not a numpy array" )
43
+ if X .ndim != 2 :
44
+ raise ValueError ("the shape is not 2D" )
45
+ max_value = None
46
+ i , j = np .array (X ).shape
44
47
45
- return i , j
48
+ max_value = None
49
+ for x in range (i ):
50
+ for y in range (j ):
51
+ cell_value = X [x ][y ]
52
+ if max_value is None or cell_value > max_value :
53
+ max_value = cell_value
54
+ i_max , j_max = x , y
55
+ return i_max , j_max
46
56
47
57
48
58
def wallis_product (n_terms ):
@@ -63,5 +73,11 @@ def wallis_product(n_terms):
63
73
The approximation of order `n_terms` of pi using the Wallis product.
64
74
"""
65
75
# XXX : The n_terms is an int that corresponds to the number of
66
- # terms in the product. For example 10000.
67
- return 0.
76
+ # terms in the product. For example 10000.*
77
+ if n_terms == 0 :
78
+ pi_approx = 2
79
+ else :
80
+ pi_approx = 2
81
+ for n in range (1 , n_terms + 1 ):
82
+ pi_approx *= (4 * n ** 2 ) / (4 * (n ** 2 ) - 1 )
83
+ return pi_approx
You can’t perform that action at this time.
0 commit comments