Skip to content
Learn Netverks

Lesson

Step 25/36 69% through track

saving-loading-npy

Saving and loading .npy files

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Saving and loading .npy files: NumPy ndarray operations, vectorization, and numerical patterns used across the Python scientific stack.

Teams apply Saving and loading .npy files in every serious NumPy project—skipping it leaves blind spots in analysis and reviews.

You will apply Saving and loading .npy files in contexts like: Notebooks, feature engineering pipelines, and custom numerical code.

Read the narrative, run `import numpy as np` snippets in the playground (install NumPy with pip if the runner lacks it), tweak shapes and dtypes, and complete MCQs.

When you can explain the previous lesson's ideas in your own words.

NumPy's native .npy format stores a single array efficiently. np.save/np.load and np.savez for multiple named arrays in one archive.

Single array

import numpy as np
a = np.array([1, 2, 3])
# np.save('data.npy', a)
# b = np.load('data.npy')
print('Use save/load in local projects')

Multiple arrays

np.savez('archive.npz', X=X, y=y) bundles arrays. Load with data = np.load('archive.npz'); data['X'].

Playground cannot write files—practice locally with notebooks.

Alternatives

  • CSV — human-readable, slow, lossy for floats
  • Parquet — via Pandas/pyarrow for tables
  • HDF5 — large scientific datasets

Important interview questions and answers

  1. Q: Why .npy over pickle?
    A: Npy is array-specific, faster, safer—no arbitrary code execution on load.
  2. Q: savez_compressed?
    A: Adds zlib compression—smaller disk at CPU cost.

Self-check

  1. Which function loads a .npy file?
  2. How do you save two arrays X and y in one file?

Tip: Practice np.save/np.load locally—playground has no disk writes.

Interview prep

npy vs pickle?

Npy is array-specific, faster, safer—no arbitrary code execution.

savez?

Multiple named arrays in one .npz archive.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • npy vs npz?
  • Pickle arrays?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump