Arrays from Lists
np.array turns nested lists into arrays. Each level adds a dimension.
Example
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a)
print(a.shape)
print(np.array([1, 2]).shape, np.array(5).ndim)Result
[[1 2 3] [4 5 6]] (2, 3) (2,) 0
Exercise
Nested lists.
np.([[1, 2], [3, 4]])
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.