Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add N-Dimensional Array Creator snippet #260

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

Open
Debanjan110d wants to merge 4 commits into quicksnip-dev:main
base: main
Choose a base branch
Loading
from Debanjan110d:n-dimensional-array-snippet
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update N-Dimensional Array Creator snippet to match guidelines
  • Loading branch information
Debanjan110d committed Feb 17, 2025
commit d6230284af6fb6d99e78b06967e9483fce347658
16 changes: 7 additions & 9 deletions snippets/python/[numpy}/n_dimensional_array.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ tags: numpy, arrays, python, n-dimensional
```py
import numpy as np

n = int(input("Enter the number of dimensions: "))
n_dim_array = np.array([1])
n_dim_array = n_dim_array.reshape(*([1] * n))
def create_n_dimensional_array(n, fill_value=1):
"""Creates an N-dimensional NumPy array filled with a given value."""
return np.full([1] * n, fill_value)

print(f"Created an {n}-dimensional array.")
print(f"Number of dimensions: {n_dim_array.ndim}")

# Usage:
# -> Run the script and enter the number of dimensions.
# -> It will create an N-dimensional array and display its number of dimensions.
# Example usage:
Copy link
Collaborator

@Mathys-Gasnier Mathys-Gasnier Mar 10, 2025

Choose a reason for hiding this comment

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

the usage comment should be # Usage: to follow our standard

Copy link
Author

@Debanjan110d Debanjan110d Mar 12, 2025

Choose a reason for hiding this comment

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

Ok

# arr = create_n_dimensional_array(3)
# print(arr.ndim) # Output: 3
```

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /