知识卡片
内存映射会被复制操作物化
memmap可按需访问磁盘映射,但转置后copy、tolist再构造数组会产生副本和Python对象,可能改变数据类型与峰值内存。要保留映射优势,应追踪每一步是否复制及何时访问数据,不能见到起点为memmap便称全流程恒定内存。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
>>> vecs = np.array(mmvecs.T.copy().tolist()) >>> variables = dict(vecs=vecs, v=v) >>> dt_vectorized = timeit('v.dot(vecs)', globals=variables, number=20) >>> dt_vectorized 0.106... #1 Memory-mapped files require you to know the shape of your arrays ahead of time. It took a little more than 100 milliseconds to perform 3.2 million multiplications and additions. A total of 41,531 × 384 (1.6 million) multiplications are required to multiply the elements of the
参考来源
- 位置:《Natural Language Processing in Action, Second Edition》第03章《词频与逆文档频率向量》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/chapter-3.html)
- 结论依据:摘录中关于内存映射会被复制操作物化的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:>>> vecs = np.array(mmvecs.T.copy().tolist()) >>> variables = dict(vecs=vecs, v=v) >>> dt_vectorized = timeit('v.dot(vecs)', globals=variables, number=20) >>> dt_vectorized 0.106... #1 Memory-mapped files require you to know the shape of your arrays ahead of time. It took a little more than 100 milliseconds to perform 3.2 million multiplications and additions. A total of 41,531 × 384 (1.6 million) multiplications are required to multiply the elements of the