python中dtype、type()、astype()区别
(1)type()是python内置的函数。type() 返回数据结构类型(list、dict、numpy.ndarray 等)
(2)dtype 返回数据元素的数据类型(int、float等)
(3)astype() 改变np.array中所有数据元素的数据类型。
————————————
备注:
1)由于 list、dict 等可以包含不同的数据类型,因此没有dtype属性
2)np.array 中要求所有元素属于同一数据类型,因此有dtype属性
备注:能用dtype() 才能用 astype()
l1 = [1,2,4]
ar1 = np.array(l1)
print(type(l1)) #<class 'list'>
print(l1.dtype) #会报错
ar1 = np.array(l1)
print(type(a1)) #<class 'list'>
print(ar1.dtype) #会报错
注意下面的例子
ar1 = np.array(l1)
t1 = torch.from_numpy(ar1)
print(type(a1)) #<class 'numpy.ndarray'>
print(ar1.dtype) #int32
#注意print(ar1.type())会报错print(t1.type()) #torch.IntTensor
print(type(t1)) #<class 'torch.Tensor'>
print(t1.dtype) #torch.int32
#a.astype(dtype) a不变
#返回Copy of the array, cast to a specified type.
ar1 = np.arange(10,dtype=float)
ar2 = ar1.astype(np.int)
print(ar1,ar1.dtype)
print(ar2,ar2.dtype)
python中dtype、type()、astype()区别相关推荐
- python中dtype什么意思_浅谈python 中的 type(), dtype(), astype()的区别
如下所示: 函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list. ...
- python dtype什么意思_浅谈python 中的 type(), dtype(), astype()的区别
如下所示: 函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list. ...
- python中astype用法_浅谈python 中的 type(), dtype(), astype()的区别
如下所示: 函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list. ...
- 列举至少五个python内置函数和使用方法_Python内置函数 next的具体使用方法 Python中seek和next区别...
python列表本来没有next方法,为什么用iter函数生...对list用__dir__()发现没有next方法,但是用iter()生成迭代器,对该迭代next是进行迭代的方法,只有迭代器和生成器 ...
- python中arg,*arg,**kwarg区别
python中arg,*arg,**kwarg区别 1. *args(*的作用很重要) 首先要搞清楚*的意思和作用,有助于理解arg,*arg,**kwarg. (*是arg的前半部分,arg是后半部 ...
- Python中is和==的区别以及is None
0 前言 Python中有很多运算符,今天我们就来讲讲is和==两种运算符在应用上的本质区别是什么. 在讲is和==这两种运算符区别之前,首先要知道Python中对象包含的三个基本要素,分别是:id( ...
- python中的type
python中的type 我们常用type()来查看类型,使用方法如下: 1 a = "zzzq"2 b = 13 c = (1, "zzq123")4 d = ...
- python 中的 type(), dtype(), astype()的区别
函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list.dict 等 ...
- 浅谈Python中的type()、dtype()、astype()的区别
函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等)备注:1.由于 list.dict 等可 ...
- Python中辨析type/dtype/astype用法
Python中与数据类型相关函数及属性有如下三个:type/dtype/astype. 名称 描述 type() 返回参数的数据类型 dtype 返回数组中元素的数据类型 astyp ...
最新文章
- 【NCEPU】韩绘锦:图信号处理与图卷积神经网络
- 剑指OFFER之从二叉搜索树的后序遍历序列(九度OJ1367)
- MySQL 8.0 技术详解
- 【Qt】Qt中QJsonValue类
- mysql 5.6 初始化_MySQL 5.6 关于登陆的初始化设置
- django shortcut函数
- 使用dropwizard(5)--加入swagger
- Avast高级版的cleanup激活码
- SQL 插入 CLOB类型
- Mac、M1怎么安装Maven
- windows11恢复ie浏览器的方法教程
- ISP封了80和8080端口
- Oracle EBS AP付款(退款)无法产生损失(LOSS)会计分录
- VMware Workstation虚拟机安装及虚拟机搭建(内有虚拟机安装包及序列号和系统镜像)...
- python抢淘宝的东西-Python实现淘宝秒杀功能
- 又整理了一些面试相关的:视频教程,面试经验,简历模板,写简历的技巧等
- 抽象基类与接口,共性与个性的选择!
- Coding哥,魅族让你用洪荒之力来夺宝了!
- velocity单双引号区别及转义方法
- 小旋风蜘蛛池让搜狗收录快速增长