numpy IO 关于.npy文件 您所在的位置:网站首页 pycharm打开npy文件没反应 numpy IO 关于.npy文件

numpy IO 关于.npy文件

2024-07-13 15:52| 来源: 网络整理| 查看: 265

.npy文件直接打开是乱码的,其中保存的是数组,是以未压缩的原始二进制格式保存的,所以应该使用np.load()加载,就可以打印出来看了

import numpy as np b = np.load('outfile.npy') print (b)

np.savez numpy.savez() 函数将多个数组保存到以 npz 为扩展名的文件中。

numpy.savez(file, *args, **kwds) 参数说明:

file:要保存的文件,扩展名为 .npz,如果文件路径末尾没有扩展名 .npz,该扩展名会被自动加上。 args: 要保存的数组,可以使用关键字参数为数组起一个名字,非关键字参数传递的数组会自动起名为 arr_0, arr_1, … 。 kwds: 要保存的数组使用关键字名称。 实例

import numpy as np a = np.array([[1,2,3],[4,5,6]]) b = np.arange(0, 1.0, 0.1) c = np.sin(b) # c 使用了关键字参数 sin_array np.savez("runoob.npz", a, b, sin_array = c) r = np.load("runoob.npz") print(r.files) # 查看各个数组名称 print(r["arr_0"]) # 数组 a print(r["arr_1"]) # 数组 b print(r["sin_array"]) # 数组 c 输出结果为: ['sin_array', 'arr_0', 'arr_1'] [[1 2 3] [4 5 6]] [0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9] [0. 0.09983342 0.19866933 0.29552021 0.38941834 0.47942554 0.56464247 0.64421769 0.71735609 0.78332691]


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有