1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

辞書型をNumpyオブジェクトで保存する

Posted at
dic = {
  "key1": array([1,2,3]),
  "key2": array([4,5,6]),
  "key3": array([7,8,9]),
}

のような辞書型オブジェクトは、

np.savez("numpy_key_value", **dic)

もしくは

np.savez_compressed("numpy_key_value", **dic)

で保存すると

loaded = np.load("numpy_key_value.npz")
print(loaded["key1"]) #=> array([1,2,3])

というように扱えます

(詳しく検証してはいませんが、pickle.dumpよりサイズが小さくなるというようなことは無さそうだったので、サイズを気にする場合は対象データで比較することをおすすめします)

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?