@@ -37,13 +37,12 @@ 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
- #handle exceptions
41
- if not isinstance (X , np .ndarray ) :
40
+ # handle exceptions
41
+ if not isinstance (X , np .ndarray ):
42
42
raise ValueError ("The argument is not an np.array" )
43
- if np .ndim (X ) != 2 :
43
+ if np .ndim (X ) != 2 :
44
44
raise ValueError ("The matrix's dimension is not 2" )
45
45
46
-
47
46
i_max = 0
48
47
# TODO
49
48
n_samples = X .shape [0 ]
@@ -54,20 +53,19 @@ def max_index(X):
54
53
for i in range (n_samples ):
55
54
j_max = 0
56
55
for j in range (n_features - 1 ):
57
- if X [i ,j_max ] < X [i ,j + 1 ] :
56
+ if X [i , j_max ] < X [i , j + 1 ]:
58
57
j_max = j + 1
59
58
60
- max_per_line .append (X [i ,j_max ])
59
+ max_per_line .append (X [i , j_max ])
61
60
index .append (j_max )
62
61
63
- for i in range (n_samples - 1 ) :
64
- if max_per_line [i_max ] < max_per_line [i + 1 ] :
62
+ for i in range (n_samples - 1 ):
63
+ if max_per_line [i_max ] < max_per_line [i + 1 ]:
65
64
i_max = i + 1
66
65
j_max = index [i_max ]
67
66
return i_max , j_max
68
67
69
68
70
-
71
69
def wallis_product (n_terms ):
72
70
"""Implement the Wallis product to compute an approximation of pi.
73
71
@@ -90,10 +88,8 @@ def wallis_product(n_terms):
90
88
91
89
wallis = 1
92
90
93
- for i in range (1 , n_terms + 1 ):
94
- wallis = wallis * (4 * i ** 2 / (4 * i ** 2 - 1 ))
91
+ for i in range (1 , n_terms + 1 ):
92
+ wallis = wallis * (4 * i ** 2 / (4 * i ** 2 - 1 ))
95
93
pi = 2 * wallis
96
-
97
- return pi
98
94
99
- A = [ 1 , 2 , 3 ]
95
+ return pi
0 commit comments