File tree 1 file changed +16
-1
lines changed
1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 15
15
This will be enforced with `flake8`. You can check that there is no flake8
16
16
errors by calling `flake8` at the root of the repo.
17
17
"""
18
+
18
19
import numpy as np
19
20
20
21
@@ -41,6 +42,11 @@ def max_index(X):
41
42
j = 0
42
43
43
44
# TODO
45
+ if not isinstance (X , np .ndarray ):
46
+ raise ValueError ("The input is not numpy array!" )
47
+ if X .ndim != 2 :
48
+ raise ValueError ("The input is not a 2D array!" )
49
+ i , j = np .unravel_index (np .argmax (X ), X .shape )
44
50
45
51
return i , j
46
52
@@ -64,4 +70,13 @@ def wallis_product(n_terms):
64
70
"""
65
71
# XXX : The n_terms is an int that corresponds to the number of
66
72
# terms in the product. For example 10000.
67
- return 0.
73
+ if n_terms == 0 :
74
+ return 2.
75
+
76
+ product = 1.0
77
+ for i in range (1 , n_terms + 1 ):
78
+ numerator = 4 * i ** 2
79
+ denominator = (4 * i ** 2 ) - 1
80
+ product *= numerator / denominator
81
+
82
+ return 2 * product
You can’t perform that action at this time.
0 commit comments