In this article we will discuss how to create a Numpy Array of different shapes and initialized with same identical values using numpy.full().

numpy.full()

Python’s Numpy module provides a function to create a numpy array of given shape and all elements initialized with a given value,

Arguments:
shape: Shape of the new array
fill_value : Intialization value
dtype : Data type of elements | Optional

It returns a Numpy array of given shape and type, all elements in it will be initialized with fill_value.

To use Numpy in our code we need to include following module i.e.

Checkout some examples,

Example 1:

Create a 1D Numpy Array of length 10 & all elements initialized with value 5

Contents of the Create Numpy array:

Data Type of Contents of the Numpy Array : int32
Shape of the Numpy Array : (10,)

Example 2:

Create a 2D Numpy Array of 4 rows | 5 columns & all elements initialized with value 7

Contents of the Create Numpy array:

Data Type of Contents of the Numpy Array : int32
Shape of the Numpy Array : (4,5)

Example 3:

Create a 3D Numpy Array of shape (2,4,5) & all elements initialized with value 8

Contents of the Create Numpy array:

Data Type of Contents of the Numpy Array : int32
Shape of the Numpy Array : (2, 4, 5)

Example 4:

Create initialized Numpy array of specified data type

Along with initialization value, we can specify the data type too i.e.

Contents of the Create Numpy array:

Data Type of Contents of the Numpy Array : float64

Complete example is as follows,

Output:

 

If you didn't find what you were looking, then do suggest us in the comments below. We will be more than happy to add that.

Do Subscribe with us for more Articles / Tutorials like this,