简体   繁体   中英

What is the difference between array([0.]) and array([0])? [on hold]

I'm new to python and would like to know what is the difference between array([0.]) and array([0]) ? Is there any difference between them? How should I convert from array([0]) to array([0.]) ? Any help will be greatly appreciated! Thanks!

Yes, they have different data types within them:

>>> np.array([0]).dtype
dtype('int32')
>>> np.array([0.]).dtype
dtype('float64')

Whether this is important to you will depend on your use case.

To convert between them you can use np.ndarray.astype :

>>> np.array([0]).astype('float64')
array([0.])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM