Numpy empty_like()

Numpy

numpy.empty_like(prototype, dtype=None, order='K', subok=True, shape=None)
Return array of same shape and type of input proto_type.
proto_typeInput array to use shape and type
shapeInt, or sequence ( 2,3), shape of the output array
dtypedata-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()


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer