np.save/load से File में Save करना
np.save एक array को एक compact binary .npy file में लिखता है और np.load इसे exactly वैसे वापस पढ़ता है जैसे यह था।
In this page:
Syntax
np.save("file.npy", arr)
arr = np.load("file.npy")
np.save/load
.npy format array को इसके dtype और shape के साथ store करता है, इसलिए reload पर कुछ भी नहीं खोता। np.savez कई arrays को एक .npz file में bundle करता है। Binary files text से छोटी और तेज़ हैं लेकिन human-readable नहीं।
Note:
अगर आप इसे छोड़ दें np.save आपके लिए .npy extension add करता है।
उदाहरण: np.save/load
import numpy as np
import os
import tempfile
a = np.arange(6).reshape(2, 3)
path = os.path.join(tempfile.mkdtemp(), "data.npy")
np.save(path, a)
b = np.load(path)
print(b)
print("identical:", np.array_equal(a, b))
# Output:
# [[0 1 2]
# [3 4 5]]
# identical: True
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- यह उम्मीद करना कि एक .npy file एक text editor में readable होगी
- object arrays के लिए allow_pickle भूल जाना
- unintentionally एक existing file overwrite करना
चैप्टर सारांश
- save एक .npy binary file लिखता है
- load dtype और shape restore करता है
- savez कई arrays store करता है
- Human-readable नहीं
🔒
Chapter Quiz — Complete all 5 topics to unlock
0/5 topics done
Complete these topics first: