-
Notifications
You must be signed in to change notification settings - Fork 205
UP my solution #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
UP my solution #209
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,11 +37,17 @@ def max_index(X): | |
| If the input is not a numpy array or | ||
| if the shape is not 2D. | ||
| """ | ||
| 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 must be 2D") | ||
| max_val = X[0, 0] | ||
| i, j = 0, 0 | ||
| for row in range(X.shape[0]): | ||
| for col in range(X.shape[1]): | ||
| if X[row, col] > max_val: | ||
| max_val = X[row, col] | ||
| i, j = row, col | ||
|
Comment on lines
+46
to
+50
|
||
| return i, j | ||
|
|
||
|
|
||
|
|
@@ -62,6 +68,7 @@ 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) | ||
| return 2 * product | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation assumes the array has at least one element by accessing X[0, 0]. If an empty array or an array with shape (0, n) or (n, 0) is passed, this will raise an IndexError. The function should handle empty arrays gracefully, either by checking if the array has elements first or by catching this edge case.