Skip to content

Commit ae3959e

Browse files
committed
UP my solution
1 parent d31f7ef commit ae3959e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

numpy_questions.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,27 @@ def max_index(X):
3737
If the input is not a numpy array or
3838
if the shape is not 2D.
3939
"""
40+
# Vérification de la validité de X
41+
if X is None:
42+
raise ValueError("Input cannot be None.")
43+
44+
if not isinstance(X, np.ndarray):
45+
raise ValueError("Input must be a numpy array.")
46+
47+
if X.ndim != 2:
48+
raise ValueError("Input must be a 2D numpy array.")
49+
4050
i = 0
4151
j = 0
4252

53+
n_samples, n_features = X.shape
54+
max = 0
4355
# TODO
56+
for l in range(n_samples):
57+
for c in range(n_features):
58+
if X[l, c] > max:
59+
max = X[l, c]
60+
i, j = l, c
4461

4562
return i, j
4663

@@ -64,4 +81,10 @@ def wallis_product(n_terms):
6481
"""
6582
# XXX : The n_terms is an int that corresponds to the number of
6683
# terms in the product. For example 10000.
67-
return 0.
84+
if n_terms == 0:
85+
return 2
86+
87+
aprox = 2
88+
for n in range(1, n_terms + 1):
89+
aprox *= (4*n**2) / (4*n**2 - 1)
90+
return aprox

0 commit comments

Comments
 (0)