Create an Empty and a Full NumPy Array
Sometimes there is a need to create an empty and full array simultaneously for a particular question. In this situation, we have two functions named numpy.empty() and numpy. full() to create an empty and full array. Here we will see different examples:
Example 1: In the example, we create an empty array of 3X4 and a full array of 3X3 of INTEGER type.
Python3
import numpy as np # Create an empty array empa = np.empty(( 3 , 4 ), dtype = int ) print ( "Empty Array" ) print (empa) # Create a full array flla = np.full([ 3 , 3 ], 55 , dtype = int ) print ( "\n Full Array" ) print (flla) |
Output
Example 2: In the example, we create an empty array of 4X2 and a full array of 4X3 of INTEGER and FLOAT type.
Python3
# python program to create # Empty and Full Numpy arrays import numpy as np # Create an empty array empa = np.empty([ 4 , 2 ]) print ( "Empty Array" ) print (empa) # Create a full array flla = np.full([ 4 , 3 ], 95 ) print ( "\n Full Array" ) print (flla) |
Output
Example 3: In the example, we create an empty array of 3X3 and a full array of 5X3 of FLOAT type.
Python3
# python program to create # Empty and Full Numpy arrays import numpy as np # Create an empty array empa = np.empty([ 3 , 3 ]) print ( "Empty Array" ) print (empa) # Create a full array flla = np.full([ 5 , 3 ], 9.9 ) print ( "\n Full Array" ) print (flla) |
Output
How to create an empty and a full NumPy array?
NumPy is a crucial library for performing numerical computations in Python. It offers robust array objects that enable efficient manipulation and operations on extensive datasets. Creating NumPy arrays is an essential process in scientific computing and data analysis. In this article, we will explore how to create both empty and full NumPy arrays, understanding the different methods and their applications.