- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
保存 .npz
文件的 numpy.savez
的 python 文档是:
The .npz file format is a zipped archive of files named after the variables they contain. The archive is not compressed and each file in the archive contains one variable in .npy format. [...]
When opening the saved .npz file with load a NpzFile object is returned. This is a dictionary-like object which can be queried for its list of arrays (with the .files attribute), and for the arrays themselves.
我的问题是:numpy.savez
有什么意义?
保存多个数组只是一个更优雅的版本(更短的命令),还是在保存/读取过程中有加速?占用内存少吗?
最佳答案
回答您的问题有两部分解释。
正如我们已经从文档中读到的,.npy
格式是:
the standard binary file format in NumPy for persisting a single arbitrary NumPy array on disk. ... The format is designed to be as simple as possible while achieving its limited goals. (sources)
而.npz
只是一个
simple way to combine multiple arrays into a single file, one can use ZipFile to contain multiple “
.npy
” files. We recommend using the file extension “.npz
” for these archives. (sources)
因此,.npz
只是一个包含多个“.npy
”文件的 ZipFile。此 ZipFile 可以压缩(使用np.savez_compressed
)或解压缩(使用np.savez
)。
类似于tarball archive file在类 Unix 系统中,tarball 文件可以只是一个包含其他文件的未压缩归档文件,也可以是结合各种压缩程序(gzip
、bzip2
)的压缩归档文件等)
并且Numpy还提供了different APIs生成这些二进制文件输出:
np.save
---> 以NumPy .npy
格式保存数组到二进制文件np.savez
--> 以未压缩 .npz
格式将多个数组保存到一个文件中np.savez_compressed
--> 将多个数组以压缩 .npz
格式保存到一个文件中np.load
--> 从.npy
, .npz
或pickled文件中加载数组或pickled对象如果我们浏览 Numpy 的源代码,under the hood :
def _savez(file, args, kwds, compress, allow_pickle=True, pickle_kwargs=None):
...
if compress:
compression = zipfile.ZIP_DEFLATED
else:
compression = zipfile.ZIP_STORED
...
def savez(file, *args, **kwds):
_savez(file, args, kwds, False)
def savez_compressed(file, *args, **kwds):
_savez(file, args, kwds, True)
然后回到问题:
np.save
,则不会在.npy
格式之上再做压缩,只有一个存档文件,方便管理多个相关文件文件。np.savez_compressed
,那么磁盘上的内存当然会减少,因为有更多的 CPU 时间来完成压缩工作(即有点慢)。关于python - 在 python 中保存 `.npz` 文件而不是 `.npy` 在速度、内存和查找方面有什么优势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54238670/
我对构面有疑问,并根据构面进行了一些过滤。 我知道这是一个重复的问题,但我找不到答案。 我想知道如何在 flex 搜索中实现相同的功能。 假设我有一个有关汽车和某些方面的索引-例如模型和 颜色。 颜色
我正在尝试找到一种解决方案来为某些方面创建子方面列表。 我有一些产品的衣服尺码,它们存储在 solr 中 "Size_both":"W30L30","尺寸宽度":"W30","Size_length"
我正在尝试找到一种解决方案来为某些方面创建子方面列表。 我有一些产品的衣服尺码,它们存储在 solr 中 "Size_both":"W30L30","尺寸宽度":"W30","Size_length"
我对方面有疑问。他们不开火。我有小方面: @Aspect @Component public class SynchronizingAspect { @Pointcut("execution(
这是在 ruby 中启用散列自动生成的巧妙技巧(取自 facets): # File lib/core/facets/hash/autonew.rb, line 19 def self.a
这个问题在这里已经有了答案: 8年前关闭。 Possible Duplicate: Creating a facet_wrap plot with ggplot2 with different ann
XMLHttpRequest 能否从 http://mydomain.example/ 向 http://mydomain.example:81/ 发送请求? 最佳答案 要使两个文档被视为具有相同的来
我对 Elasticsearch 中的方面有一点问题。 我有一个表格视频,一个表格 channel ,一个 channel 有很多视频。 我只想在 X 个最新视频上显示每个 channel 的 %vi
假设我正在为 4 个人绘制数据图表:Alice、Bob、Chuck 和 Dana。我正在使用 ggplot2 制作一个多面图,每个人一个方面。我的磁盘上还有 4 张图像:Alice.png、Bob.p
我已经下载了收件箱,并且正在使用Pig和Hadoop处理电子邮件。我已经使用Pig和Wonderdog在ElasticSearch中为这些电子邮件编制了索引。 现在,我为收件箱中的每个电子邮件地址创建
我有一个模块如下: define([...], function(...){ function anothermethod() {...} function request() {....}
(defprotocol IAnimal "IAnimal" (report [o] (println (type o) " reporting.\n") (inner-repor
我有一个 Bean 需要向 InfluxDB 报告。数据库在表 INFLUX_DB_SERVER 中注册了 InfluxDB。如果你看一下代码,你会发现方法reportMemory做了很多工作,它构造
我的问题与分面有关。在下面的示例代码中,我查看了一些分面散点图,然后尝试在每个分面的基础上叠加信息(在本例中为平均线)。 tl;dr 版本是我的尝试失败了。要么我添加的平均线计算所有数据(不尊重方面变
假设我正在为 4 个人绘制数据图表:Alice、Bob、Chuck 和 Dana。我正在使用 ggplot2 制作一个多面图,每个人一个方面。我的磁盘上还有 4 张图像:Alice.png、Bob.p
尝试用两个方面包装服务类来获取此调用链: javanica..HystrixCommandAspect -> MyCustomAroundAspect -> MyService 遇到两个问题: Hys
我是 AspectJ 的初学者。我用它在我的网络驱动程序中截取屏幕截图。以下是我的包结构。 我想知道如何在 Browser 类中运行我的程序,以便它使用 Screenshots 类中定义的 Aspec
我在使用 spring aop 时遇到问题 (编辑:如果我的方法不是静态的,则代码可以正常工作) 我的包中有这个结构: aaa.bbb.ccc.Clase1.java aaa.bbb.ddd.Clas
我有一个通用存储库类,其中包含各种标记有 PostSharp 方面 (SecuredOperation) 的方法... public class Repository : IRepository, I
我有一个运行多线程的 Hibernate 事务方法“doImportImpl”。而某些记录需要依次导入,所以代码结构大致是这样的: public RecordResult doImportImpl(S
我是一名优秀的程序员,十分优秀!