What Is an Array?
ndarray vs. Python list, and the core ways to create one.
A Python list can hold anything and grow freely, but it's slow for
math and doesn't understand "elementwise" operations. NumPy's core type,
ndarray (n-dimensional array), trades that flexibility for speed: every
element is the same fixed , packed contiguously in
memory, so operations run as fast, C
loops instead of a Python for loop.
That's the single most important mental shift coming from plain Python:
operators act elementwise on arrays. a * 2 doubles every element;
a + b adds them pairwise (as long as their
agree; more on in Lesson 3).
| Function | What it makes | Example |
|---|---|---|
| an array from existing data |
|
| filled with 0s / 1s |
|
| filled with a constant |
|
| like |
|
|
|
|
| the n×n identity matrix |
|
Now practice it
Exercises that use what this lesson just covered.