Movatterモバイル変換


[0]ホーム

URL:


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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Debanjan110d wants to merge4 commits intoquicksnip-dev:main
base:main
Choose a base branch
Loading
fromDebanjan110d:n-dimensional-array-snippet
Open
Show file tree
Hide file tree
Changes fromall commits
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
19 changes: 19 additions & 0 deletionssnippets/python/[numpy]/n_dimensional_array.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
---
title: N-Dimensional Array Creator
description: Creates an N-dimensional array filled with a single element.
author: Debanjan110d
tags: numpy, arrays, python, n-dimensional
---

```py
import numpy as np

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)

# Usage example
if __name__ == '__main__':
array = create_n_dimensional_array(n=3, fill_value=10)
print(array)
```
18 changes: 18 additions & 0 deletionssnippets/python/[numpy}/n_dimensional_array.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
---
title: N-Dimensional Array Creator
description: Creates an N-dimensional array filled with a single element.
author: Debanjan110d
tags: numpy, arrays, python, n-dimensional
---

```py
import numpy as np

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)

# Example usage:
Copy link
Collaborator

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

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
```

[8]ページ先頭

©2009-2025 Movatter.jp