Skip to content

Commit 5440084

Browse files
committed
UP my solution
1 parent 2b6d947 commit 5440084

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

numpy_questions.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ def max_index(X):
3737
If the input is not a numpy array or
3838
if the shape is not 2D.
3939
"""
40-
#handle exceptions
41-
if not isinstance(X, np.ndarray) :
40+
# handle exceptions
41+
if not isinstance(X, np.ndarray):
4242
raise ValueError("The argument is not an np.array")
43-
if np.ndim(X) != 2 :
43+
if np.ndim(X) != 2:
4444
raise ValueError("The matrix's dimension is not 2")
4545

46-
4746
i_max = 0
4847
# TODO
4948
n_samples = X.shape[0]
@@ -54,20 +53,19 @@ def max_index(X):
5453
for i in range(n_samples):
5554
j_max = 0
5655
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]:
5857
j_max = j+1
5958

60-
max_per_line.append(X[i,j_max])
59+
max_per_line.append(X[i, j_max])
6160
index.append(j_max)
6261

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]:
6564
i_max = i+1
6665
j_max = index[i_max]
6766
return i_max, j_max
6867

6968

70-
7169
def wallis_product(n_terms):
7270
"""Implement the Wallis product to compute an approximation of pi.
7371
@@ -90,10 +88,8 @@ def wallis_product(n_terms):
9088

9189
wallis = 1
9290

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))
9593
pi = 2*wallis
96-
97-
return pi
9894

99-
A = [1, 2,3]
95+
return pi

0 commit comments

Comments
 (0)