NumPy 1.8 introduced np.full(), which is a more direct method than empty() followed by fill() for creating an array filled with a certain value:

>>> np.full((3, 5), 7)
array([[ 7.,  7.,  7.,  7.,  7.],
       [ 7.,  7.,  7.,  7.,  7.],
       [ 7.,  7.,  7.,  7.,  7.]])

>>> np.full((3, 5), 7, dtype=int)
array([[7, 7, 7, 7, 7],
       [7, 7, 7, 7, 7],
       [7, 7, 7, 7, 7]])

This is arguably the way of creating an array filled with certain values, because it explicitly describes what is being achieved (and it can in principle be very efficient since it performs a very specific task).

Answer from Eric O. Lebigot on Stack Overflow
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.fill.html
numpy.ndarray.fill — NumPy v2.1 Manual
Fill expects a scalar value and always behaves the same as assigning to a single array element. The following is a rare example where this distinction is important: >>> a = np.array([None, None], dtype=object) >>> a[0] = np.array(3) >>> a array([array(3), None], dtype=object) >>> a.fill(np.array(3)) >>> a array([array(3), array(3)], dtype=object)
🌐
Programming Idioms
programming-idioms.org › idiom › 314 › fill-array-with-value › 7592 › python
Fill array with value, in Python
August 25, 2022 - set_all_elements_to_same_value(X, V) :- length(X, Length), length(FilledList, Length), maplist(=(V), FilledList, X).
🌐
Delft Stack
delftstack.com › home › howto › numpy › python fill array with value
How to Fill Array With Value in NumPy | Delft Stack
March 11, 2025 - In this example, we first import the NumPy library and define the shape of our array as a tuple (3, 4), meaning we want a 3x4 array. We set the fill_value to 7. The np.full() function then creates a new array of the specified shape, filled entirely ...
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.fill.html
numpy.ndarray.fill — NumPy v2.5 Manual
Fill expects a scalar value and always behaves the same as assigning to a single array element. The following is a rare example where this distinction is important: >>> a = np.array([None, None], dtype=np.object_) >>> a[0] = np.array(3) >>> a array([array(3), None], dtype=object) >>> a.fill(np.array(3)) >>> a array([array(3), array(3)], dtype=object)
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-ndarray-fill-in-python
numpy.ndarray.fill() in Python - GeeksforGeeks
December 28, 2018 - DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 28 Dec, 2018 · numpy.ndarray.fill() method is used to fill the numpy array with a scalar value.
Find elsewhere
🌐
OpenSourceOptions
opensourceoptions.com › fill-numpy-arrays-with-numpy-fill-and-numpy-full
Fill NumPy Arrays with numpy.fill and numpy.full – OpenSourceOptions
Your values will be slightly different. Again, for a description of creating arrays with NumPy visit my guide. It will explain the creation methods used in this tutorial. array([7.56603881e-307, 6.23054972e-307, 6.23053954e-307, 1.02360052e-306, 1.78020984e-306]) Now, let’s fill that array with a specified value using numpy.fill().
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.ndarray.fill.html
numpy.ndarray.fill — NumPy v2.6.dev0 Manual
Fill expects a scalar value and always behaves the same as assigning to a single array element. The following is a rare example where this distinction is important: >>> a = np.array([None, None], dtype=np.object_) >>> a[0] = np.array(3) >>> a array([array(3), None], dtype=object) >>> a.fill(np.array(3)) >>> a array([array(3), array(3)], dtype=object)
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.ndarray.fill.html
numpy.ndarray.fill — NumPy v2.0 Manual
Fill expects a scalar value and always behaves the same as assigning to a single array element. The following is a rare example where this distinction is important: >>> a = np.array([None, None], dtype=object) >>> a[0] = np.array(3) >>> a array([array(3), None], dtype=object) >>> a.fill(np.array(3)) >>> a array([array(3), array(3)], dtype=object)
🌐
AskPython
askpython.com › python › array › initialize-a-python-array
3 Ways to Initialize an Array in Python - AskPython
3 weeks ago - The NumPy dtype controls how each entry is represented. Without an explicit dtype, zeros produces floating-point values, which print with decimal points. An integer dtype matches calculations that expect whole-number values. For a constant other than zero, np.full() takes the requested shape and fill value.
🌐
Statology
statology.org › home › how to fill numpy array with values (2 examples)
How to Fill NumPy Array with Values (2 Examples)
July 21, 2022 - The following code shows how to use the np.full() function to fill up a NumPy array of length 10 with the value 3 in each position:
🌐
Codecademy
codecademy.com › docs › python:numpy › ndarray › .fill()
Python:NumPy | ndarray | .fill() | Codecademy
October 29, 2025 - The .fill() method is used to fill a NumPy array with a specified scalar value. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
🌐
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 - Today, I’m going to show you how to numpy create array with same value using various methods. The easiest way to create an array filled with the same value is by using NumPy’s numpy.full() function.
🌐
Python.org
discuss.python.org › ideas › list/bytearray fill with single value/object
List/bytearray fill with single value/object - Ideas - Discussions on Python.org
November 22, 2025 - Similar to Numpy slice assignment and C++ std:fill for example, it would be useful to be able to fill a list or bytearray object with a constant value/object. For example: some_list[:] = 0 or: some_list.fill(None, startpos, endpos) The fastest method seems to be to just re-allocate the object, but that is not always desirable/convenient.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.fill.html
numpy.ndarray.fill — NumPy v2.2 Manual
Fill expects a scalar value and always behaves the same as assigning to a single array element. The following is a rare example where this distinction is important: >>> a = np.array([None, None], dtype=object) >>> a[0] = np.array(3) >>> a array([array(3), None], dtype=object) >>> a.fill(np.array(3)) >>> a array([array(3), array(3)], dtype=object)
🌐
datagy
datagy.io › home › numpy › numpy full: create arrays with a fill value
NumPy full: Create Arrays With a Fill Value • datagy
December 30, 2022 - NumPy makes it very easy to create one-dimensional arrays filled with a given value. This can be done by passing a single integer into the shape= parameter. This allows you to specify the length of the resulting array.
🌐
Stack Overflow
stackoverflow.com › questions › 49103167 › python-filling-an-array-with-calculated-values
Python - Filling an array with calculated values - Stack Overflow
x = np.linspace(-2, 2, 100) print("\nx values:\n ", x) f2y = np.zeros(len(x)) # print("f2y, empty array of y values: ", f2y) for i in range(0, len(x), 1): for j in x: f2y[i] = f2(j) The f2y array is supposed to fill up with different y-values based on what x value is plugged in.