Skip to content

Commit a90bda9

Browse files
committed
Update numpy_questions.py
1 parent 27734de commit a90bda9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

numpy_questions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
def max_index(X):
2222
"""Return the index of the maximum in a numpy array.
23-
dsvsdf
2423
Parameters
2524
----------
2625
X : ndarray of shape (n_samples, n_features)
@@ -41,8 +40,13 @@ def max_index(X):
4140
j = 0
4241

4342
# TODO
44-
43+
if not isinstance(X, np.ndarray):
44+
raise ValueError("Input is not a numpy array")
45+
if X.ndim != 2:
46+
raise ValueError("Input is not a 2D array")
47+
i, j = np.unravel_index(np.argmax(X), X.shape)
4548
return i, j
49+
4650

4751

4852
def wallis_product(n_terms):

0 commit comments

Comments
 (0)