File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Expand file tree Collapse file tree 1 file changed +16
-8
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
21
- def max_index (X ) :
22
+ def max_index (x : np . ndarray ) -> tuple :
22
23
"""Return the index of the maximum in a numpy array.
23
24
24
25
Parameters
25
26
----------
26
- X : ndarray of shape (n_samples, n_features)
27
+ x : ndarray of shape (n_samples, n_features)
27
28
The input array.
28
29
29
30
Returns
30
31
-------
31
32
(i, j) : tuple(int)
32
- The row and columnd index of the maximum.
33
+ The row and column index of the maximum.
33
34
34
35
Raises
35
36
------
36
37
ValueError
37
38
If the input is not a numpy array or
38
39
if the shape is not 2D.
39
40
"""
40
- i = 0
41
- j = 0
42
-
43
- # TODO
41
+ if not isinstance ( x , np . ndarray ):
42
+ raise ValueError ( "Input must be a numpy array" )
43
+ if x . ndim != 2 :
44
+ raise ValueError ( "Input array must be 2D" )
44
45
46
+ # index = x.argmax()
47
+ # i = index // x.shape[1]
48
+ # j = index % x.shape[1]
49
+ i , j = np .unravel_index (np .argmax (x ), x .shape )
45
50
return i , j
46
51
47
52
@@ -64,4 +69,7 @@ def wallis_product(n_terms):
64
69
"""
65
70
# XXX : The n_terms is an int that corresponds to the number of
66
71
# terms in the product. For example 10000.
67
- return 0.
72
+ pi = 1.0
73
+ for i in range (1 , n_terms + 1 ):
74
+ pi *= (4 * i ** 2 ) / (4 * i ** 2 - 1 )
75
+ return 2 * pi
You can’t perform that action at this time.
0 commit comments