前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python中astype用法_python里的astype是什么意思?

python中astype用法_python里的astype是什么意思?

作者头像
全栈程序员站长
发布2022-06-27 09:55:45
9.3K0
发布2022-06-27 09:55:45
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

展开全部

astype是实现2113变量类型转换,例如

astype(type): returns a copy of the array converted to the specified type.a =

a.astype(‘Float64’)b = b.astype(‘Int32’)

Python中与数据5261类型4102相关函数及属性1653有如下三个:type/dtype/astype

type() 返回参数的数据类型

dtype 返回数组中元素的数据类型

astype() 对数据类型进行转换

python中type dtype astype 的用法

1,type 获取数据类型

2,dtype 数组元素的类型

resize,m_lfit,w_600,h_800,limit_1
resize,m_lfit,w_600,h_800,limit_1

3,astype 修改数据类型

resize,m_lfit,w_600,h_800,limit_1
resize,m_lfit,w_600,h_800,limit_1

扩展资料

python里的astype的运用代码:

#astype的应用

e=np.linspace(1,5,20)

print(e)

#>>>

[1. 1.21052632 1.42105263 1.63157895 1.84210526 2.05263158

2.26315789 2.47368421 2.68421053 2.89473684 3.10526316 3.31578947

3.52631579 3.73684211 3.94736842 4.15789474 4.36842105 4.57894737

4.78947368 5. ]

”’

print(e.dtype)

#>>>float64

e=e.astype(int)

print(e)

#>>>[1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 5]

print(e.dtype)

#>>>int64

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/133413.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年6月9,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档