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 |
import numpy as np
ar=np.array([4,7,9])
ar=np.empty_like(ar)
print(ar)
Output
[4 7 9]
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]
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()Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.