The numpy module of Python provides a function called numpy.empty(). This function is used to create an array without initializing the entries of given shape and type.
Just like numpy.zeros(), the numpy.empty() function doesn't set the array values to zero, and it is quite faster than the numpy.zeros(). This function requires the user to set all the values in the array manually and should be used with caution.
numpy.empty(shape, dtype=float, order='C')
shape: int or tuple of ints
This parameter defines the shape of the empty array, such as (3, 2) or (3, 3).
dtype: data-type(optional)
This parameter defines the data type, which is desired for the output array.
order: {'C', 'F'}(optional)
This parameter defines the order in which the multi-dimensional array is going to be stored either in row-major or column-major. By default, the order parameter is set to 'C'.
This function returns the array of uninitialized data that have the shape, dtype, and order defined in the function.
import numpy as np x = np.empty([3, 2]) x
Output:
In the above code
import numpy as np x = np.empty([3, 3], dtype=float) x
Output:
import numpy as np x = np.empty([3, 3], dtype=float, order='C') x
Output:
In the above code
In the output, it shows an array of uninitialized values of defined shape, data type, and order.
import numpy as np x = np.empty([3, 3], dtype=float, order='F') x
Output: