Skip to content

Comments

UP my solution#209

Open
amineouat wants to merge 1 commit intox-datascience-datacamp:mainfrom
amineouat:amineouat
Open

UP my solution#209
amineouat wants to merge 1 commit intox-datascience-datacamp:mainfrom
amineouat:amineouat

Conversation

@amineouat
Copy link

No description provided.

Copilot AI review requested due to automatic review settings December 17, 2025 10:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements two skeleton functions in a NumPy assignment: max_index to find the maximum element's position in a 2D array, and wallis_product to approximate π using the Wallis product formula.

Key changes:

  • Implemented max_index with input validation and nested loop traversal to find the maximum value's indices
  • Implemented wallis_product using the mathematical formula π/2 = ∏(4n²)/(4n²-1)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +46 to +50
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
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested loop implementation is inefficient for finding the maximum index in a numpy array. NumPy provides built-in optimized functions like np.argmax() or np.unravel_index() that are significantly faster and more idiomatic. Using these would avoid the O(n*m) Python loop overhead and leverage NumPy's vectorized operations.

Copilot uses AI. Check for mistakes.
raise ValueError("Input must be a numpy array")
if X.ndim != 2:
raise ValueError("Input must be 2D")
max_val = X[0, 0]
Copy link

Copilot AI Dec 17, 2025

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant