Array Creation and Properties
np.array(), np.zeros/ones/eye/arange/linspace, shape, dtype, ndim, size.
The ndarray
NumPy's core object is the ndarray: a fixed-size, homogeneous grid of numbers stored in contiguous memory. This layout is what makes NumPy fast.
import numpy as np
a = np.array([1, 2, 3, 4])
print(a) # [1 2 3 4]From Nested Lists
Pass a list of lists to build a 2D array. NumPy infers the shape from the structure.
m = np.array([[1, 2, 3], [4, 5, 6]])
print(m)
# [[1 2 3]
# [4 5 6]]All lessons in this course
- Array Creation and Properties
- Indexing, Slicing, and Fancy Indexing
- Broadcasting and Vectorized Operations
- Linear Algebra with NumPy