简体   繁体   English

array([0。])和array([0])有什么区别? [等候接听]

[英]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]) ? 我是python的新手,想知道array([0.])array([0])什么区别? Is there any difference between them? 它们之间有什么区别吗? How should I convert from array([0]) to array([0.]) ? 我应该如何从array([0])转换为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.ndarray.astype

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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