File tree Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Original file line number Diff line number Diff line change @@ -29,26 +29,23 @@ def max_index(X):
29
29
Returns
30
30
-------
31
31
(i, j) : tuple(int)
32
- The row and columnd index of the maximum.
32
+ The row and column index of the maximum.
33
33
34
34
Raises
35
35
------
36
36
ValueError
37
37
If the input is not a numpy array or
38
38
if the shape is not 2D.
39
39
"""
40
- i = 0
41
- j = 0
42
-
43
- # TODO
44
- X = np .array (X )
45
- rowMax = np .max (X , axis = 1 )
46
- maxValue = np .max (rowMax )
47
- indices = np .where (X == maxValue )
48
- i = indices [0 ][0 ]
49
- j = indices [1 ][0 ]
50
-
51
- return i , j
40
+ if not isinstance (X , np .ndarray ):
41
+ raise ValueError ("The input must be a numpy array." )
42
+
43
+ if X .ndim != 2 :
44
+ raise ValueError ("The input array must be 2D." )
45
+
46
+ max_idx = np .unravel_index (np .argmax (X , axis = None ), X .shape )
47
+
48
+ return max_idx
52
49
53
50
54
51
def wallis_product (n_terms ):
You can’t perform that action at this time.
0 commit comments