python 包含数组的字典的快速保持与读取
Posted 志行千里90
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 包含数组的字典的快速保持与读取相关的知识,希望对你有一定的参考价值。
import numpy as np
以某多光谱影像各波段的旋转矩阵为例,为了方便后续快速读取,可以采用以下方法:
1 、保存
dict = {‘0’: array([[ 1.00183113e+00, 2.42887095e-03, -6.52577667e+00],
[ 6.24892114e-04, 1.00231696e+00, 3.62381647e+00],
[ 1.03694726e-06, 3.33383843e-06, 1.00000000e+00]]), ‘1’: array([[ 9.99010339e-01, 1.68270278e-04, -6.60596664e+00],
[-1.16404090e-03, 1.00123064e+00, -1.87048194e-01],
[-2.16003652e-06, -1.84603231e-07, 1.00000000e+00]]), ‘2’: array([[ 9.91527200e-01, -4.00050243e-04, 1.16473537e+00],
[-2.39671892e-03, 9.97187844e-01, 5.51014110e+00],
[-4.03302705e-06, 1.37676457e-06, 1.00000000e+00]]), ‘3’: array([[ 1.00000000e+00, -2.40627930e-16, 2.95211121e-13],
[ 3.59715794e-19, 1.00000000e+00, 1.00777808e-13],
[ 2.95278150e-21, -2.80083458e-19, 1.00000000e+00]]), ‘4’: array([[ 9.92618027e-01, 5.62925990e-04, 1.63811202e+00],
[-1.05907639e-03, 9.94077852e-01, 4.32428207e+00],
[-1.26180554e-06, 7.65431976e-07, 1.00000000e+00]])}
np.save(‘dict .npy’, dictionary)
2 读取
read_dictionary = np.load(’‘dict .npy’,allow_pickle=True).item()
print(read_dictionary[‘0’]) #
[[ 1.00183113e+00 2.42887095e-03 -6.52577667e+00]
[ 6.24892114e-04 1.00231696e+00 3.62381647e+00]
[ 1.03694726e-06 3.33383843e-06 1.00000000e+00]]
以上是关于python 包含数组的字典的快速保持与读取的主要内容,如果未能解决你的问题,请参考以下文章