Skip to content

Commit e9f7253

Browse files
committed
UP my solution
1 parent d31f7ef commit e9f7253

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

numpy_questions.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,22 @@ def max_index(X):
3737
If the input is not a numpy array or
3838
if the shape is not 2D.
3939
"""
40+
if X is None:
41+
raise ValueError('None not allowed')
42+
if not isinstance(X, np.ndarray):
43+
raise ValueError('input must be numy array')
44+
if X.ndim != 2:
45+
raise ValueError('must be 2D')
4046
i = 0
4147
j = 0
42-
43-
# TODO
48+
max_ = X[i][j]
49+
n_samples = len(X)
50+
n_features = len(X[0])
51+
for sample in range(n_samples):
52+
for feature in range(n_features):
53+
if X[sample][feature] > max_:
54+
max_ = X[sample][feature]
55+
i, j = sample, feature
4456

4557
return i, j
4658

@@ -64,4 +76,7 @@ def wallis_product(n_terms):
6476
"""
6577
# XXX : The n_terms is an int that corresponds to the number of
6678
# terms in the product. For example 10000.
67-
return 0.
79+
product = 1.
80+
for i in range(1, n_terms+1):
81+
product *= (4*(i**2))/(4*(i**2)-1)
82+
return product*2

0 commit comments

Comments
 (0)