欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

numpy 字典的保存与读取 npy文件

程序员文章站 2022-05-18 19:14:33
...
import numpy as np

# 将字典数据保存为.npy文件
imgNameList = []
locationSet = []
location_dict = dict(zip(imgNameList, locationSet)) #生成字典
file_name = cropped_save_path.split('/')[-1]
print(file_name)
np.save(cropped_save_path + '/' + str(file_name) + '.npy', location_dict) #保存

# 读取.npy文件里的字典
npy_path = r"C:\Users\tianr\Desktop\Research\Img_ROI_M270\Img_ROI_M270.npy"
load_data = np.load(npy_path, allow_pickle=True)
print(type(load_data))
print(load_data)
print(load_data.item().get('0001')) #根据键取值

 

相关标签: NumPy python