首页 > 其他 > 详细

NumPy ndarray data type

时间:2020-01-31 11:50:26      阅读:84      评论:0      收藏:0      [点我收藏+]

原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/12244852.html

 

dtype

The data type or dtype is a special object containing the information (or metadata, data about data) the ndarray needs to interpret a chunk of memory as a particular type of data:

技术分享图片

 

NumPy data types

技术分享图片

you can use shorthand type code strings to create ndarray

arr = np.array([1.1, 2.2, 3.3], dtype=f8)

 

astype

You can explicitly convert or cast an array from one dtype to another using ndarray’s astype method. 

Calling astype always creates a new array (a copy of the data), even if the new dtype is the same as the old dtype.

integer -> float

技术分享图片

float -> integer

技术分享图片

string -> float

技术分享图片

Note: If casting were to fail for some reason (like a string that cannot be converted to float64), a ValueError will be raised.

 

Reference

Python for Data Analysis Second Edition

 

NumPy ndarray data type

原文:https://www.cnblogs.com/agilestyle/p/12244852.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!