Python 中的 astype() 和 .dtype
这里主要介绍 astype(), .dtype看以下就能懂(下面包含 .dtype)
.dtype 就是显示数据类型的一种方法
astype() 的作用
转换 numpy 数组的数据类型, 因此如果数据是 tensor 类型的数据, 就需要先将数据转换为 numpy.array 类型再进行转换
示例
import torch
import numpy as npa = torch.rand(2, 2)
print(a.numpy().astype('uint8').dtype)
print(a)
print(a.numpy().astype('float32').dtype)
print(a)>>uint8
>>tensor([[0.4651, 0.8008],[0.8621, 0.3698]])
>>float32
>>tensor([[0.4651, 0.8008],[0.8621, 0.3698]])
注意
在使用 astype() 函数时, 想要变换的类型必须加引号
Python 中的 astype() 和 .dtype相关推荐
- python中dtype什么意思_NumPy Python中的数据类型对象(dtype)
每个ndarray都有一个关联的数据类型(dtype)对象.此数据类型对象(dtype)告知我们有关数组布局的信息.这意味着它为我们提供了有关以下信息: 数据类型(整数,浮点数,Python对象等) ...
- 浅谈Python中的type()、dtype()、astype()的区别
函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等)备注:1.由于 list.dict 等可 ...
- python中dtype什么意思_浅谈python 中的 type(), dtype(), astype()的区别
如下所示: 函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list. ...
- python中type(),dtype(),astype()的区别
python中type(),dtype(),astype()的区别 type(): 返回的是数据结构的类型(list, dict,numpy.ndarry) >>> k = [1, ...
- Python中辨析type/dtype/astype用法
Python中与数据类型相关函数及属性有如下三个:type/dtype/astype. 名称 描述 type() 返回参数的数据类型 dtype 返回数组中元素的数据类型 astyp ...
- Python中type/dtype/astype用法
Python中与数据类型相关函数及属性有如下三个:type/dtype/astype. 名称 描述 type() 返回参数的数据类型 dtype 返回数组中元素的数据类型 astype() 对数据类型 ...
- 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中dtype的使用规范_Python numpy.dtype() 使用实例
参考链接: Python中的numpy.extract The following are code examples for showing how to use . They are extrac ...
最新文章
- (六)java多线程之ReadWriteLock
- c语言求n个数的最小值博客,C语言中的#define宏定义 求一组数的最大值和最小值(转)...
- IEEE754标准中32位、64位浮点数的取值范围
- 网易云音乐测开面试题整理
- [蓝桥杯][2018年第九届真题]日志统计(树状数组)
- 开发工具:VSCode 摸鱼神器,确定不试一下?
- java并发队列_Java并发教程–阻塞队列
- 程序员如何才算真正的高效编程?
- 20161120-安全测试
- 从pandas到geopandas
- SDK中利用COM打印helloworld时报错DONE pin is not high on target FPGA的一种可能的解决办法
- java学习之Eclipse开发工具
- 求解偏微分方程开源有限元软件deal.II学习--Step 5
- 用代码排出自己的名字
- 第十届“中国电机工程学会杯”全国大学生电工数学建模竞赛 B 题 全面二孩政策对我国人口结构的影响
- 1x pcie 速度_PCIe传输速率计算方法
- 【SaaS培训认证】AWS Solutions Architect Associate
- 如何看懂congestion map
- android内核调试
- html模态框插件,如何使用JavaScript构建模态框插件
热门文章
- 计算文件及字符串的VBS脚本
- HTTPS证书过期|SSL证书过期 |华硕路由器| NAS|Certtificate is not valid
- 脱离文档流和恢复文档流的方法
- C语言七巧板游戏制作,七巧板具体玩法与制作方法详解
- 如何用妙记多 Mojidoc 设置子弹笔记
- textarea内容换行,textarea中换行符br失效
- 2021年中国奶粉行业发展现状分析,行业集中度不断提升,下沉市场发展空间广阔「图」
- 【广州数据报表中心怎么样】什么样的大数据
- 只有养老机器人才能拯救未来“老龄化中国”
- Spring @InitBinder注解