当前位置:网站首页>【Numpy】解决:关于 dtype=object 的含义及坑点
【Numpy】解决:关于 dtype=object 的含义及坑点
2022-08-06 13:58:00 【翁诗浩】
0.直接上两段代码:
C o d e 1 : Code1: Code1:
import numpy as np
a = []
e = 0.3
a.append(['s1', 's2', 's3', float(e)])
a = np.array(a)
print(type(a[0, 3]))
输出结果为: 输出结果为: 输出结果为:<class 'numpy.str_'>
C o d e 2 : Code2: Code2:
import numpy as np
a = []
e = 0.3
a.append(['s1', 's2', 's3', float(e)])
a = np.array(a,dtype=object)
print(type(a[0, 3]))
输出结果为: 输出结果为: 输出结果为:<class 'float'>
1.解释:
n u m p y numpy numpy数组存储为连续的内存块。它们通常有单一的数据类型(例如整数、浮点数或固定长度的字符串),然后内存中的位被解释为具有该数据类型的值。
创建 d t y p e = o b j e c t dtype=object dtype=object的数组是不同的。数组占用的内存现在充满了存储在内存其他地方的 P y t h o n Python Python对象的指针(很像 P y t h o n Python Python列表实际上只是对象指针的列表,而不是对象本身)。
2.文档原话:
n u m p y numpy numpy arrays are stored as contiguous blocks of memory. They usually have a single datatype (e.g. integers, floats or fixed-length strings) and then the bits in memory are interpreted as values with that datatype.
Creating an array with d t y p e = o b j e c t dtype=object dtype=object is different. The memory taken by the array now is filled with pointers to P y t h o n Python Python objects which are being stored elsewhere in memory (much like a P y t h o n Python Python list is really just a list of pointers to objects, not the objects themselves).
3.存在的坑点:
如 C o d e 1 Code1 Code1所示,如果多 a p p e n d append append几行后要对 n u m p y numpy numpy矩阵按照第三列排序时使用np.argsort()函数时 p y t h o n python python会默认按照str类型的字典序排序,影响最终排序结果!!!!且你如果不懂的话很难发现!!
22.08.04 22.08.04 22.08.04
* H a p p y C h i n e s e V a l e n t i n e ′ s D a y c h u i c h u i * \hearts Happy\ Chinese\ Valentine's\ Day_{\ chui\ chui}\hearts *Happy Chinese Valentine′s Day chui chui*
边栏推荐
猜你喜欢

40 degrees high temperature, how to find the coolest place indoors through SOLIDWORKS?

机器学习笔记(吴恩达老师)

Rocket MQ Crash-Safe机制浅析

【直播预告】对话知道创宇丨如何守住内容安全生命线?

智慧城市系列-1

微服务中如何切换配置文件、部署

【 TypeScript will learn will be 】 you must know all about TypeScript

TcpServer::start都做了些什么

接口流量突增,如果是你,怎样做好性能调优?

LeetCode 热题 HOT 100(2.两数相加)
随机推荐
池塘cPond分享会第5期 • 守望者联盟 • 巴比特副总裁马千里 • 数字艺术对Web3的价值...
redis数据类型及常用命令
自然语言处理的前世、今生和未来
40度高温,如何通过SOLIDWORKS找到室内最凉快的地方?
MODBUS转PROFINET网关将电力智能监控仪表接入PROFINET网络案例
机器学习笔记(吴恩达老师)
ERC4907 的到来 会给 NFT 带来哪些变革?
七夕了,给你的那个TA画上一箭倾心吧~
Kubernetes Cluster Ingress Gateway
力扣练习——47 二叉树中的最大路径和
R语言ggplot2可视化:可视化多分类变量箱图(Box Plot)、自定义箱图箱体的填充色、添加主标题、副标题、题注信息
Talking about Tree Arrays
typeindex类型支持库学习
安全第六天课后练习
重写muduo网络库开发环境和前期准备
redis use
梅科尔工作室OpenHarmony设备开发培训笔记-第5章学习笔记
[TypeScript] In-depth study of TypeScript decorators
Panda
力扣练习——51 搜索二维矩阵