numpy.empty_like() in Python
The empty_like() method of Python numpy class returns a new array with the same shape and type as the specified array.
Syntax
numpy.empty_like(prototype, dtype=None, order='K', subok=True)
Parameters
The numpy. empty_like() method consists of four parameters, which are as follows:
prototype : The shape and data-type of prototype define the attributes of the returned array.
order : The order parameter can be either C_contiguous or F_contiguous
dtype : It is an optional parameter. It depicts the data type of returned array, and by default, it is a float.
subok : It is an optional Boolean argument that is used to make a subclass of type ‘a’ or not. By default, it is true.
Return Value
The numpy.empty_like() method returns an array with the same shape and type as the given array.
Example 1
# Python Programming giving an example for
# numpy. empty_like() method
import numpy as numpy
obj = numpy.empty_like([2, 2], dtype = int)
print("\nMatrix obj : \n", obj)
obj1 = obj = ([1,2,3], [4,5,6])
print("\nMatrix obj1 : \n", numpy.empty_like(obj1))
Output
Matrix obj :
[140332201097160 31509568]
Matrix obj1 :
[[140332201097144 140332201097144 0]
[ 33 28688496 140332201097160]]