切片numpy加载文件如何加载到内存中 [英] How slicing numpy load file is loaded into memory

查看:52
本文介绍了切片numpy加载文件如何加载到内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想使用 numpy.load 加载文件的一部分,我使用切片为:

If I want to load a portion of a file using numpy.load, I use slicing as:

np.load('myfile.npy')[start:end].

这是否保证文件中的这一部分,即 [start:end],只加载到内存中,还是先加载整个文件然后切片?

Does this guarantee that this portion from the file, i.e., [start:end], is only loaded into to memory or does it load the entire file first then slice it?

谢谢,

推荐答案

这加载了整个事情.如果您不想加载整个内容,您可以映射文件并只复制您想要的部分:

That loads the whole thing. If you don't want to load the whole thing, you could mmap the file and only copy the part you want:

part = numpy.load('myfile.npy', mmap_mode='r')[start:end].copy()

这篇关于切片numpy加载文件如何加载到内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆