Skip to content

Commit

Permalink
UP my solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-selini committed Dec 18, 2023
1 parent d31f7ef commit 8869ef7
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/2023-assignment-numpy.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions numpy_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def max_index(X):
i = 0
j = 0

# TODO
if not isinstance(X, np.ndarray) or X.ndim != 2:
raise ValueError("Input must be a 2D numpy array")

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

return i, j

Expand All @@ -64,4 +67,16 @@ def wallis_product(n_terms):
"""
# XXX : The n_terms is an int that corresponds to the number of
# terms in the product. For example 10000.
return 0.

if n_terms == 0:
return 2.0

result = 1.0
for i in range(1, n_terms + 1):
term = 4.0 * i ** 2
result *= term / (term - 1)

# Multiply by 2 to get the final Wallis product
pi_approximation = 2 * result

return pi_approximation
1 change: 1 addition & 0 deletions test_numpy_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ def test_wallis_product():

pi_approx = wallis_product(100000)
assert abs(pi_approx - m.pi) < 1e-4

0 comments on commit 8869ef7

Please sign in to comment.