本文簡要介紹 python 語言中 numpy.savez_compressed
的用法。
用法:
numpy.savez_compressed(file, *args, **kwds)
以壓縮的
.npz
格式將多個數組保存到一個文件中。提供數組作為關鍵字參數,以將它們存儲在輸出文件中的相應名稱下:
savez(fn, x=x, y=y)
。如果數組被指定為位置參數,即,
savez(fn, x, y)
,他們的名字將是arr_0,arr_1, 等等。- file: 字符串或文件
將保存數據的文件名(字符串)或打開的文件(file-like 對象)。如果文件是一個字符串或一個路徑,
.npz
擴展名將被附加到文件名(如果它不存在)。- args: 參數,可選
要保存到文件的數組。請使用關鍵字參數(參見下麵的 kwds)為數組分配名稱。指定為 args 的數組將命名為 “arr_0”、“arr_1” 等。
- kwds: 關鍵字參數,可選
要保存到文件的數組。每個數組都將以其對應的關鍵字名稱保存到輸出文件中。
- None
參數:
返回:
注意:
.npz
文件格式是文件的壓縮存檔,以它們包含的變量命名。存檔使用zipfile.ZIP_DEFLATED
壓縮,並且存檔中的每個文件都包含一個.npy
格式的變量。有關.npy
格式的說明,請參閱numpy.lib.format
。打開保存的時候
.npz
文件與numpy.load a NpzFile對象被返回。這是一個類似字典的對象,可以查詢其數組列表(使用.files
屬性),以及數組本身。例子:
>>> test_array = np.random.rand(3, 2) >>> test_vector = np.random.rand(4) >>> np.savez_compressed('/tmp/123', a=test_array, b=test_vector) >>> loaded = np.load('/tmp/123.npz') >>> print(np.array_equal(test_array, loaded['a'])) True >>> print(np.array_equal(test_vector, loaded['b'])) True
相關用法
- Python numpy savez用法及代碼示例
- Python numpy save用法及代碼示例
- Python numpy savetxt用法及代碼示例
- Python numpy searchsorted用法及代碼示例
- Python numpy shape用法及代碼示例
- Python numpy scimath.log用法及代碼示例
- Python numpy signbit用法及代碼示例
- Python numpy setdiff1d用法及代碼示例
- Python numpy seterr用法及代碼示例
- Python numpy sort用法及代碼示例
- Python numpy scimath.logn用法及代碼示例
- Python numpy square用法及代碼示例
- Python numpy std用法及代碼示例
- Python numpy scimath.log2用法及代碼示例
- Python numpy sum用法及代碼示例
- Python numpy spacing用法及代碼示例
- Python numpy seterrobj用法及代碼示例
- Python numpy squeeze用法及代碼示例
- Python numpy scimath.arccos用法及代碼示例
- Python numpy shares_memory用法及代碼示例
- Python numpy s_用法及代碼示例
- Python numpy swapaxes用法及代碼示例
- Python numpy sctype2char用法及代碼示例
- Python numpy show_config用法及代碼示例
- Python numpy set_printoptions用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.savez_compressed。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。