简体   繁体   English

从泡菜文件中加载前n个项目

[英]Load the first n items from a pickle file

This may be an unusual thing to do, but I would like to load n items from a pckle file, it can be random, or first or last items. 这可能是不寻常的事情,但是我想从一个pckle文件中加载n个项目,它可以是随机的,也可以是第一个或最后一个项目。

The reason is that I am testing a neural network that load the pickle file as data and I want the network to run a lot faster (reducing from 100000 items to n) in the testing phase. 原因是我正在测试一个将泡菜文件作为数据加载的神经网络,并且我希望该网络在测试阶段可以运行得更快(从100000项减少到n项)。

Right now I am loading the pickle as: 现在,我将泡菜装载为:

l = pickle.load(open(file, 'rb'))

Is there any parameter to load only the first n items? 是否有任何参数仅加载前n个项目?

The file looks like this: 该文件如下所示:

在此处输入图片说明

This was quite easy actually: 实际上,这很容易:

n = 100;
l = pickle.load(open(file, 'rb'))[1:n];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM