Skip to content

Commit fb72a90

Browse files
UP my solution
1 parent d31f7ef commit fb72a90

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

numpy_questions.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
"""Assignment - using numpy and making a PR.
24
35
The goals of this assignment are:
@@ -15,7 +17,12 @@
1517
This will be enforced with `flake8`. You can check that there is no flake8
1618
errors by calling `flake8` at the root of the repo.
1719
"""
18-
import numpy as np
20+
21+
import os
22+
23+
os.chdir(
24+
"/Users/martinsimonoviez/Desktop/IODAA" +
25+
"/cours/datacamp-master/2024-assignment-numpy")
1926

2027

2128
def max_index(X):
@@ -37,12 +44,20 @@ def max_index(X):
3744
If the input is not a numpy array or
3845
if the shape is not 2D.
3946
"""
47+
if "numpy" in str(type(X)):
48+
raise ValueError('None')
49+
if X.ndim != 2:
50+
raise ValueError('Not in 2D')
4051
i = 0
4152
j = 0
42-
43-
# TODO
44-
45-
return i, j
53+
max_local = X[0, 0]
54+
for k in range(X.shape[0]):
55+
for m in range(X.shape[1]):
56+
if X[k, m] > max_local:
57+
max_local = X[k, m]
58+
i = k
59+
j = m
60+
return(i, j)
4661

4762

4863
def wallis_product(n_terms):
@@ -62,6 +77,9 @@ def wallis_product(n_terms):
6277
pi : float
6378
The approximation of order `n_terms` of pi using the Wallis product.
6479
"""
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.
80+
# XXX : The n_terms is an int that corresponds to the number of
81+
# terms in the product. For example 10000.
82+
resultat = 2
83+
for k in range(n_terms):
84+
resultat = resultat*(4*((k+1)**2)/((4*((k+1)**2)-1)))
85+
return resultat

0 commit comments

Comments
 (0)