How to create NumPy array using empty() & eye() functions?

Today we are going to learn how to create a 1-D array using NumPy library functions. We will learn empty() and eye() functions. so let us begin.

1. Using Empty() function

Numpy has one more function that can be used to create and initialize an array.The function name is empty().When you create an array you can create it with empty() and populate the desired values at runtime. It just reserves the places for the number of columns and number of rows for you.

Let us understand empty() function with an example:

import numpy as np
array_six = np.empty((3,3))  
print("array six using empty",array_six)

The output of the above program will look like:

array six using empty 
 [[0.00000000e+000 0.00000000e+000 9.76118064e-313]
 [1.95820216e-306 6.23054972e-307 8.90106955e-307]
 [1.20161797e-306 1.86920872e-306 1.08225056e-312]]

2.Using eye() function

eye() is another function that is available in NumPy library that is used to create a matrix with x*x size and all the elements in the diagonal are 1.

Let us understand this with an example:

import numpy as np
array_seven = np.eye(3)
print("Eye function output:",array_seven)

The output of the above program will look like this:

Eye function output:
 [[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 1.]]