python读取查看npz
时间: 2023-05-26 10:06:55 浏览: 156
文件
可以使用numpy.load()函数来读取npz文件中的数据,并使用print()函数等来查看数据。
例如,假设我们有一个名为data.npz的文件,其中包含两个数组a和b,可以使用以下代码来读取和查看这些数组:
```python
import numpy as np
# load the data from 'data.npz' file
data = np.load('data.npz')
# get the 'a' array from the loaded data
a = data['a']
# print the shape of 'a' array
print('Shape of a:', a.shape)
# print the values of 'a' array
print('Values of a:', a)
# get the 'b' array from the loaded data
b = data['b']
# print the shape of 'b' array
print('Shape of b:', b.shape)
# print the values of 'b' array
print('Values of b:', b)
```
输出结果可能如下所示:
```
Shape of a: (2, 3)
Values of a: [[1 2 3]
[4 5 6]]
Shape of b: (3,)
Values of b: [10 20 30]
```
注意,读取npz文件中的数据会将其全部读入内存,因此需要确保文件不会过大导致内存不足。
阅读全文
相关推荐


















