np.save
numpy.save(file, arr, allow_pickle=True, fix_imports=True)
-
file:file, str, or pathlib.Path
儲存檔名或路徑。
-
arr:array_like
要保存的NumPy陣列變數資料。
寫入 .npy 檔
with open("test.npy", "wb") as f:
np.save(f, np.array([1, 2]))
np.save(f, np.array([1, 3]))
讀取 .npy 檔
with open("test.npy", "rb") as f:
a = np.load(f)
b = np.load(f)
print(a, b)
# [1 2] [1 3]
np.savez
numpy.savez(file, *args, **kwds)
-
file:str or file
儲存檔名或路徑。
-
args:Arguments, optional
要保存NumPy陣列變數資料。會自動使用關鍵字參數(請參閱下面的 kwds)為陣列分配名稱。指定為 args 的數組將命名為“arr_0”、“arr_1”等。
-
kwds:Keyword arguments, optional
要保存到文件的數組。每個數組都將保存到輸出文件及其對應的關鍵字名稱。
使用 *args 參數來儲存 (會預設名稱)
np.savez(outfile, x, y)
_ = outfile.seek(0) # Only needed here to simulate closing & reopening file
npzfile = np.load(outfile)
npzfile.files
['arr_0', 'arr_1']
npzfile['arr_0']
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
使用 **kwds 參數來儲存 (自定義名稱)
outfile = TemporaryFile()
np.savez(outfile, x=x, y=y)
_ = outfile.seek(0)
npzfile = np.load(outfile)
sorted(npzfile.files)
['x', 'y']
npzfile['x']
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
參考
2,327 則留言
DonDonHax
dark web sites darkmarket 2025
TolikLoF
dark web markets darknet market
JosephSom
purchase generic cialis TadalAccess cialis reviews
Donaldhacle
darknet markets darkmarket url
DonDonHax
darkmarket link darknet markets