NumPy ndarray data type


原创转载请注明出处: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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM