(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()区别相关推荐

  1. python中dtype什么意思_浅谈python 中的 type(), dtype(), astype()的区别

    如下所示: 函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list. ...

  2. python dtype什么意思_浅谈python 中的 type(), dtype(), astype()的区别

    如下所示: 函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list. ...

  3. python中astype用法_浅谈python 中的 type(), dtype(), astype()的区别

    如下所示: 函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list. ...

  4. 列举至少五个python内置函数和使用方法_Python内置函数 next的具体使用方法 Python中seek和next区别...

    python列表本来没有next方法,为什么用iter函数生...对list用__dir__()发现没有next方法,但是用iter()生成迭代器,对该迭代next是进行迭代的方法,只有迭代器和生成器 ...

  5. python中arg,*arg,**kwarg区别

    python中arg,*arg,**kwarg区别 1. *args(*的作用很重要) 首先要搞清楚*的意思和作用,有助于理解arg,*arg,**kwarg. (*是arg的前半部分,arg是后半部 ...

  6. Python中is和==的区别以及is None

    0 前言 Python中有很多运算符,今天我们就来讲讲is和==两种运算符在应用上的本质区别是什么. 在讲is和==这两种运算符区别之前,首先要知道Python中对象包含的三个基本要素,分别是:id( ...

  7. python中的type

    python中的type 我们常用type()来查看类型,使用方法如下: 1 a = "zzzq"2 b = 13 c = (1, "zzq123")4 d = ...

  8. python 中的 type(), dtype(), astype()的区别

    函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list.dict 等 ...

  9. 浅谈Python中的type()、dtype()、astype()的区别

    函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等)备注:1.由于 list.dict 等可 ...

  10. Python中辨析type/dtype/astype用法

    Python中与数据类型相关函数及属性有如下三个:type/dtype/astype. 名称    描述 type()    返回参数的数据类型 dtype    返回数组中元素的数据类型 astyp ...

最新文章

  1. 【NCEPU】韩绘锦:图信号处理与图卷积神经网络
  2. 剑指OFFER之从二叉搜索树的后序遍历序列(九度OJ1367)
  3. MySQL 8.0 技术详解
  4. 【Qt】Qt中QJsonValue类
  5. mysql 5.6 初始化_MySQL 5.6 关于登陆的初始化设置
  6. django shortcut函数
  7. 使用dropwizard(5)--加入swagger
  8. Avast高级版的cleanup激活码
  9. SQL 插入 CLOB类型
  10. Mac、M1怎么安装Maven
  11. windows11恢复ie浏览器的方法教程
  12. ISP封了80和8080端口
  13. Oracle EBS AP付款(退款)无法产生损失(LOSS)会计分录
  14. VMware Workstation虚拟机安装及虚拟机搭建(内有虚拟机安装包及序列号和系统镜像)...
  15. python抢淘宝的东西-Python实现淘宝秒杀功能
  16. 又整理了一些面试相关的:视频教程,面试经验,简历模板,写简历的技巧等
  17. 抽象基类与接口,共性与个性的选择!
  18. Coding哥,魅族让你用洪荒之力来夺宝了!
  19. velocity单双引号区别及转义方法
  20. 小旋风蜘蛛池让搜狗收录快速增长

热门文章

  1. spring容器是什么
  2. ReactNative 网络请求失败
  3. 【PI应用】用Java查询雅虎天气并解析Json数据
  4. 谷歌注册大陆手机号不可用
  5. 小说里的编程 【连载之二十六】元宇宙里月亮弯弯
  6. 读《3D打印:从想象到现实》后感
  7. 另一个小程序 返回的支付结果如何得到_如何高效对接第三方支付
  8. win10计算机文件夹怎么去掉,Win10如何去除此电脑中的6个文件夹
  9. ArcGIS制作区位图教程
  10. js打包文件生成zip