0PricingLogin
Learn AI with Python · Lesson

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

  1. Array Creation and Properties
  2. Indexing, Slicing, and Fancy Indexing
  3. Broadcasting and Vectorized Operations
  4. Linear Algebra with NumPy
← Back to Learn AI with Python