Skip to content

Commit

Permalink
Numpy solve
Browse files Browse the repository at this point in the history
  • Loading branch information
YassineLoulou committed Dec 20, 2024
1 parent d31f7ef commit 46c73e5
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions numpy_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ def max_index(X):
i = 0
j = 0

# TODO
if not isinstance(X, np.ndarray):
raise ValueError("Input must be a numpy array.")

if X.ndim != 2:
raise ValueError("Input array must be 2-dimensional.")

max_idx = np.unravel_index(np.argmax(X), X.shape)
i, j = max_idx

return i, j

Expand All @@ -62,6 +69,11 @@ def wallis_product(n_terms):
pi : float
The approximation of order `n_terms` of pi using the Wallis product.
"""
# XXX : The n_terms is an int that corresponds to the number of
# terms in the product. For example 10000.
return 0.
product = 1.0

for n in range(1, n_terms + 1):
product *= (4 * n ** 2) / ((4 * n ** 2) - 1)

pi = product * 2

return pi

0 comments on commit 46c73e5

Please sign in to comment.