numpy.empty_like(prototype, dtype=None, order='K', subok=True, shape=None)
Return array of same shape and type of input proto_type.
proto_type | Input array to use shape and type |
shape | Int, or sequence ( 2,3), shape of the output array |
dtype | data-type( Optional ), Data Type of returned array. |
order | {'C','F'} Optional, how the output is to be stored. C- style or Fortan style |
Examples
import numpy as np
ar=np.array([4,7,9])
ar=np.empty_like(ar)
print(ar)
Output
[4 7 9]
dtype
import numpy as np
ar=np.array([4,7,9])
ar_l=np.empty_like(ar,dtype=np.int64)
print(ar_l)
Output
[4 7 9]
dtype=str
import numpy as np
ar=np.array([4,7,9])
ar_l=np.empty_like(ar,dtype=str)
print(ar_l)
Output
['' '' '']
dtype=float
import numpy as np
ar=np.array([4,7,9])
ar_l=np.empty_like(ar,dtype=float)
print(ar_l)
Output
[2.0e-323 3.5e-323 4.4e-323]
Using shape
import numpy as np
ar=np.array([4,7,9])
ar_l=np.empty_like(ar,shape=(2,3))
print(ar_l)
Output
[[36598224 0 0]
[ 0 0 0]]
empty()
«Numpy
eye()
bincount()
arange()
linspace()
← Subscribe to our YouTube Channel here