Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions snippets/python/[numpy}/n_dimensional_array.md
Original file line number Diff line number Diff 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
```