Let’s say we want to create a NumPy array with a specific shape. And we want to fill the entries of the NumPy array with a specific number. We can do so easily using the numpy.full() function.
For example, we can use the following Python code to create a NumPy array with shape (2, 3) that is filled with the float value 1.2.
import numpy a = numpy.full(shape=(2, 3), fill_value=1.2, dtype=numpy.float64) print(a)
Here, the shape argument of the numpy.full() function denotes the shape of the created array. In this example, shape=(2, 3) means the shape of the created array is (2, 3). In other words, the created array will have 2 rows and 3 elements in each row.
The fill_value argument denotes the value of each element of the NumPy array. Here, each element of the NumPy array will have the value 1.2.
And the dtype argument specifies the data type of each element of the array. If no value is given for the dtype argument, then the data type of the fill_value argument is taken by default.
The output of the mentioned program will be:
[[1.2 1.2 1.2] [1.2 1.2 1.2]]






0 Comments