Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Saving and loading NumPy arrays is easy! 💾

12.3K views on YouTube

#python #coding #numpy

00:00:00 save NumPy array
00:01:53 load NumPy array
00:02:30 save multiple arrays
00:04:29 savez_compressed()
00:05:01 load multiple arrays

import numpy as np

# ——————————————–
# Save a NumPy array
# ——————————————–
array = np.array([[1, 2, 3], [4, 5, 6]])
np.save(“data”, array)
print(“File saved!”)

# ——————————————–
# Load a single NumPy array
# ——————————————–
array = np.load(“data.npy”)
print(array)

# ——————————————–
# Save multiple NumPy arrays
# ——————————————–
array1 = np.array([[1, 2, 3], [4, 5, 6]])
array2 = np.array([2022, 2023, 2024, 2025])
array3 = np.array([1.1, 2.2, 3.3, 4.4, 5.5])

np.savez(“data”, array1, array2, array3)

print(“NumPy data was saved!”)

# ——————————————–
# Load multiple NumPy arrays
# ——————————————–
arrays = np.load(“data.npz”)

print(arrays[“arr_0”])
print(arrays[“arr_1”])
print(arrays[“arr_2”])