학습 자료

Generating Arrays (arange, linspace, zeros, ones)

NumPy gives you built-in functions to quickly create arrays — without manually typing the values.

These are useful for building test data or initializing arrays.


np.arange(start, stop, step)

Creates evenly spaced values from start to stop (excluding stop).

np.arange(0, 10, 2) # [0 2 4 6 8]

np.linspace(start, stop, num)

Creates a specific number of evenly spaced values including the stop value.

np.linspace(0, 1, 5) # [0. 0.25 0.5 0.75 1.0]

np.zeros(shape) and np.ones(shape)

Create arrays filled with all 0s or all 1s. Pass in a shape like (3,) or (2, 3).

np.zeros((2, 2)) # [[0. 0.] # [0. 0.]]

Summary

  • arange: spaced by step (like range())
  • linspace: spaced by number of points
  • zeros / ones: fill arrays with fixed values

What’s Next

You’ll now try generating different types of arrays using these tools in Jupyter.

Quiz
0 / 1

Using NumPy's array creation functions

The `np.linspace` function is used to create spaced values, including the final value.
randomly
evenly
randomly with a step
unevenly

학습 자료

AI 튜터

디자인

업로드

수업 노트

즐겨찾기

도움말