Skip to content
Learn Netverks

Lesson

Step 6/36 17% through track

ndarray-creation

Creating ndarrays

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Creating ndarrays: NumPy ndarray operations, vectorization, and numerical patterns used across the Python scientific stack.

Teams apply Creating ndarrays in every serious NumPy project—skipping it leaves blind spots in analysis and reviews.

You will apply Creating ndarrays 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 offers many ways to create arrays: from Python sequences, with factory functions like zeros and arange, or by reshaping existing buffers.

From Python sequences

import numpy as np
a = np.array([1, 2, 3])
b = np.array([[1, 2], [3, 4]])
print(a.shape, b.shape)

Factory functions

  • np.zeros(shape) — array of zeros
  • np.ones(shape) — array of ones
  • np.full(shape, fill_value) — constant fill
  • np.arange(start, stop, step) — like range
  • np.linspace(start, stop, num) — evenly spaced floats
  • np.eye(n) — identity matrix

dtype at creation

Pass dtype= to control element type: int32, float64, bool. Untyped literals infer from input values.

Important interview questions and answers

  1. Q: arange vs linspace?
    A: arange uses step size; linspace specifies count of points including endpoints.
  2. Q: Why np.array([1,2,3]) not just list?
    A: Converts to ndarray with vectorized methods and contiguous storage.

Self-check

  1. Create a 3×3 identity matrix.
  2. What function gives 10 evenly spaced values from 0 to 1?

Tip: Prefer np.array with explicit dtype at boundaries.

Interview prep

zeros vs empty?

zeros fills 0; empty allocates uninitialized memory—use empty for speed when overwriting.

linspace vs arange?

linspace specifies count; arange specifies step.

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

  • np.array vs zeros?
  • arange use case?

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