If by "array" you actually mean a Python list, you can use

a = [0] * 10

or

a = [None] * 10
Answer from Sven Marnach on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-initialize-empty-array-of-given-length
Python - Initialize empty array of given length - GeeksforGeeks
In this method, we can use the repeat() function from the itertools module to create a new iterator that returns the same value a certain number of times. This can be used to create an empty array of a specific size by providing a value of None and the desired length.
Published: July 12, 2025
Discussions

Implementing Array[T, N] in Python
def sum(v: Array[int, int]) -> int: More on reddit.com
๐ŸŒ r/learnpython
2
1
May 16, 2023
Initialising an array of fixed size in Python - Stack Overflow
Python copies "plain old data types" by value, and the rest by reference, and it's not always clear when one or the other is happening. 2020-01-13T14:31:04.37Z+00:00 ... in case anyone wondering, the behavior is (TLDR first multiplier creates n length array, second multiplier creates a list ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to create an n-length array?
So the first is a janky solution similar to what you've done (don't do this in R unless you have good reasons for doing so). Just use seq. odd_array <- function(x,y){ init_arr <- array(data = NA, dim = length(x:y)) for (i in x:y){ if (i %% 2 != 0){ init_arr <- append(init_arr,i) } } return(init_arr[!is.na(init_arr)]) assign("output",init_arr, envir = globalenv()) } odd_array(1,100) Do this! seq(1,99,2) More on reddit.com
๐ŸŒ r/rprogramming
3
1
September 22, 2021
How should I initialize a numpy array of NaN values?
>>> np.full(3, np.nan) But the bigger question is why would you want to? Edit: as an explanation, your example does not work because you initialized an array of ints. ints have no "NaN" value, only floats do. So your method would work if you initialized an array of floats: >>> x = np.array([0.0,0.0,0.0]) >>> x.fill(np.nan) >>> x array([ nan, nan, nan]) Or converted the ints to floats: >>> x = np.array([0,0,0], dtype=np.float) >>> x.fill(np.nan) >>> x array([ nan, nan, nan]) But the np.full() method is much better. More on reddit.com
๐ŸŒ r/learnpython
5
5
April 8, 2016
๐ŸŒ
Quora
quora.com โ€บ How-do-I-create-an-array-of-a-specific-size-in-Python
How to create an array of a specific size in Python - Quora
Answer (1 of 3): (1) In Python, you donโ€™t typically work with arrays, but with lists. There are libraries to work with arrays, but you only use them for certain specialized purposes. Such as when you need matrix multiplication or some other advanced math, and want to do it quickly.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.5 โ€บ user โ€บ basics.creation.html
Array creation โ€” NumPy v2.5 Manual
In the third example, the array is dtype=np.float64 to accommodate the step size of 0.1. Due to roundoff error, the stop value is sometimes included. numpy.linspace will create arrays with a specified number of elements, and spaced equally between the specified beginning and end values.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_arrays.asp
Python Arrays
You refer to an array element by referring to the index number. ... Use the len() method to return the length of an array (the number of elements in an array).
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ array.html
array โ€” Efficient arrays of numeric values
The typecode character used to create the array. ... The length in bytes of one array item in the internal representation. ... Append a new item with the specified value to the end of the array. ... Return a tuple (address, length) giving the current memory address and the length in elements of the buffer used to hold arrayโ€™s contents. The size ...
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ watch
declare array of size n in python
To learn more, please visit the YouTube Help Center: https://www.youtube.com/help
๐ŸŒ
Mimo
mimo.org โ€บ tutorials โ€บ python โ€บ how-to-create-an-array-in-python
How to Create an Array in Python
Create arrays in Python with lists, array.array, or NumPy, based on whether you need flexibility, fixed numeric types, or fast math.
๐ŸŒ
Career Karma
careerkarma.com โ€บ blog โ€บ python โ€บ python: initialize list of size n
Python: Initialize List of Size N: A Complete Guide | Career Karma
December 1, 2023 - We can initialize a list of size n using a range() statement. The difference between using a range() statement and the None method is that a range() statement will create a list of values between two numbers.
๐ŸŒ
Pp4rs
pp4rs.github.io โ€บ pp4rs-python โ€บ notebooks โ€บ numpy โ€บ 01-create_array.html
Numpy Basics - Creating Arrays โ€” Python for Economics and Business Research
Note that i indicates that the contents of my_array are integers, whilst f indicates the contents of another_array are floating point numbers. Pythonโ€™s array module offers an efficient way os storing arrays, but we will often want to perform operations on, or with, the data stored in an array.
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ user โ€บ basics.creation.html
Array creation โ€” NumPy v2.6.dev0 Manual
In the third example, the array is dtype=np.float64 to accommodate the step size of 0.1. Due to roundoff error, the stop value is sometimes included. numpy.linspace will create arrays with a specified number of elements, and spaced equally between the specified beginning and end values.
๐ŸŒ
Medium
medium.com โ€บ @amit25173 โ€บ trick-to-quickly-numpy-create-array-with-same-value-5fac963d3921
Trick to Quickly numpy create array with same value | by Amit Yadav | Medium
April 12, 2025 - import numpy as np # Create an array of shape (3, 4) filled with the value 7 array_with_value = np.full((3, 4), 7) print(array_with_value) You see that? It creates a 3x4 array with every element being 7. You can replace 7 with any other value you need, whether it's a string, a float, or any number. You might be wondering: what if I want to create an array of ones or zeros?
๐ŸŒ
H2K Infosys
h2kinfosys.com โ€บ home โ€บ python tutorials โ€บ mastering range of numbers in array with numpy: arange & linspace simplified
Mastering Range of Numbers in Array with Numpy: arange & linspace Simplified | H2K Infosys Blog
March 22, 2021 - The linspace function in Python, part of the NumPy library, is used to generate an array of evenly spaced numbers over a specified range. It is particularly useful for creating sequences of numbers for mathematical computations and plotting.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-create-a-python-list-of-size-n
Python - Create List of Size n - GeeksforGeeks
July 23, 2025 - Another easy way to create a list of size n is by using list comprehension. It is very flexible, allowing us to create a list with any values or even based on a condition. ... # Size of the list n = 5 # Creating a list of size n using list ...
๐ŸŒ
Python Course
python-course.eu โ€บ numerical-programming โ€บ creating-numpy-arrays.php
2. Creating Numpy Arrays | Numerical Programming | python-course.eu
March 24, 2022 - You might have guessed by now that the new shape must correspond to the number of elements of the array, i.e. the total size of the new array must be the same as the old one.
๐ŸŒ
Real Python
realpython.com โ€บ np-linspace-numpy
np.linspace(): Create Evenly or Non-Evenly Spaced Arrays โ€“ Real Python
July 3, 2026 - In this tutorial, you'll learn how to use NumPy's np.linspace() effectively to create an evenly or non-evenly spaced range of numbers. You'll explore several practical examples of the function's many uses in numerical applications.
๐ŸŒ
Medium
giulio-laurenti.medium.com โ€บ different-ways-to-create-arrays-in-numpy-d0fbfbfca99c
Different Ways to Create Arrays in NumPy | by Giulio Laurenti, PhD | Medium
September 25, 2024 - # Create an array containing the scalar 23. a1 = np.array(23) print(a1) 23 # If we do not use the print function, the output will look like below a1 array(23) # Create an array containing a list. l = [1, 2, 3, 4] a2 = np.array(l) a2 array([1, 2, 3, 4]) # It is also possible to use complex nested sequences such as lists of lists. l4 = [[[1, 2, 3, 4], [5, 6, 7, 8]], [[11, 12, 13, 14], [15, 16, 17, 18]]] a4 = np.array(l4) a4 array([[[ 1, 2, 3, 4], [ 5, 6, 7, 8]], [[11, 12, 13, 14], [15, 16, 17, 18]]]) # If the list had different lenght, Python would return an error.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ implementing array[t, n] in python
r/learnpython on Reddit: Implementing Array[T, N] in Python
May 16, 2023 -

As a challenge, I want to implement an Array type in Python.

This type should have two generic parameters. The first parameter should be another type, and the second parameter should be a numeric value that indicates the size of the array. For example, I could write:

def sum(v: Array[int, 3]) -> int:
    return v[0] + v[1] + v[2]  # + v[3] will result in a type-check error

Unfortunately, using integral values as parameters for generic types is unsupported in mypy. There is an open and seemingly abandoned issue related to this problem: https://github.com/python/mypy/issues/3345.

However, it appears that by implementing __class_getitem__, I can generate a valid Array type at runtime, allowing me to write Python code with an Array type. Moreover, I believe that by implementing a mypy plugin, I can enable type-checking for code that uses this new Array type.

I haven't pursued this approach because I quickly realized that I have no idea how to implement functions that accept an array of any size, such as a size function that should return N for Array[T, N]. I'm wondering if there's a way to implement such a class as valid Python code that can be type-checked.

One approach I've considered is introducing a new function similar to TypeVar, called IntegerVar. By writing n = IntegerVar("n"), the code def foo(a: Array[int, n]) is valid Python code as long as I implement __class_getitem__ correctly. With enough effort, my mypy plugin might be able to correctly type-check this function. Unfortunately, this means I won't be able to use the actual value of n inside the code, which is a shame (e.g., for the size function mentioned above).

I'm sure I'm not the first person to think about this issue, so I'm wondering:

  1. Am I missing something? Is it possible to implement an Array in Python without jumping through hoops?

  2. If not, can anyone provide me with some direction on how I could implement this type while still allowing myself to write functions that are generic over the size of the array?

  3. Are there any good tutorials or introductions for implementing mypy plugins available?

๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-add-to-array
Python Array Add: How to Append, Extend & Insert Elements | DigitalOcean
Learn how to add to an array in Python with append(), extend(), insert(), and NumPy. Compare lists vs arrays, avoid common errors, and see tested examples.