【发布时间】:2015-11-23 18:37:37
【问题描述】:
在最后一个示例中,使用带有 **kwds 的 savez,数组与关键字名称一起保存。
outfile = TemporaryFile()
np.savez(outfile, x=x, y=y)
outfile.seek(0)
npzfile = np.load(outfile)
npzfile.files
['y', 'x']
npzfile['x']
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
我将如何使用变量的实际值,例如:
x_name = 'foo'
y_name = 'bar'
np.savez(outfile, x_name=x, y_name=y)
然后
npzfile.files
['foo', 'bar']
【问题讨论】:
-
npzfile.foo和.bar的实际内容从何而来? -
我正在从文件路径中读取一堆图像并提取描述符,理想情况下,我希望字典中的键(图像文件名)与描述符匹配。明白我的意思了吗?
标签: python arrays numpy keyword