Skip to content

Commit 7b7d105

Browse files
committed
Up my solution
1 parent d31f7ef commit 7b7d105

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

numpy_questions.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The goals of this assignment are:
44
* Use numpy in practice with two easy exercises.
55
* Use automated tools to validate the code (`pytest` and `flake8`)
6-
* Submit a Pull-Request on github to practice `git`.
6+
* Submit a Pull-Request on gitHub to practice `git`.
77
88
The two functions below are skeleton functions. The docstrings explain what
99
are the inputs, the outputs and the expected error. Fill the function to
@@ -15,6 +15,7 @@
1515
This will be enforced with `flake8`. You can check that there is no flake8
1616
errors by calling `flake8` at the root of the repo.
1717
"""
18+
1819
import numpy as np
1920

2021

@@ -41,6 +42,19 @@ def max_index(X):
4142
j = 0
4243

4344
# TODO
45+
if not isinstance(X, np.ndarray):
46+
raise ValueError("L'argument doit être une numpy array.")
47+
48+
forme = X.shape
49+
50+
if len(forme) != 2:
51+
raise ValueError("L'argument doit être en 2D.")
52+
53+
n_samples, n_features = forme
54+
55+
index = np.argmax(X)
56+
i = int(index // n_features)
57+
j = int(index % n_features)
4458

4559
return i, j
4660

@@ -62,6 +76,11 @@ def wallis_product(n_terms):
6276
pi : float
6377
The approximation of order `n_terms` of pi using the Wallis product.
6478
"""
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.
79+
if n_terms == 0:
80+
return 2
81+
82+
wal_pro = 1
83+
for i in range(1, n_terms + 1):
84+
wal_pro *= (4 * i ** 2) / ((4 * i ** 2) - 1)
85+
86+
return wal_pro * 2.

0 commit comments

Comments
 (0)