File tree Expand file tree Collapse file tree 1 file changed +26
-8
lines changed Expand file tree Collapse file tree 1 file changed +26
-8
lines changed Original file line number Diff line number Diff line change
1
+
2
+
1
3
"""Assignment - using numpy and making a PR.
2
4
3
5
The goals of this assignment are:
15
17
This will be enforced with `flake8`. You can check that there is no flake8
16
18
errors by calling `flake8` at the root of the repo.
17
19
"""
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" )
19
26
20
27
21
28
def max_index (X ):
@@ -37,12 +44,20 @@ def max_index(X):
37
44
If the input is not a numpy array or
38
45
if the shape is not 2D.
39
46
"""
47
+ if "numpy" in str (type (X )):
48
+ raise ValueError ('None' )
49
+ if X .ndim != 2 :
50
+ raise ValueError ('Not in 2D' )
40
51
i = 0
41
52
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 )
46
61
47
62
48
63
def wallis_product (n_terms ):
@@ -62,6 +77,9 @@ def wallis_product(n_terms):
62
77
pi : float
63
78
The approximation of order `n_terms` of pi using the Wallis product.
64
79
"""
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
You can’t perform that action at this time.
0 commit comments