Loading

Quipoin Menu

Learn • Practice • Grow

python-for-ai / NumPy Arrays
tutorial

NumPy Arrays

NumPy is the fundamental library for numerical computing in Python. Its main object is the ndarray (n‑dimensional array), which stores homogeneous data (all same type) and allows fast element‑wise operations.

NumPy arrays are like Python lists, but much faster and more memory‑efficient for mathematical operations.

Creating NumPy Arrays

First, import NumPy (conventionally as np). Then create arrays from lists or using built‑in functions.
import numpy as np

# From a list
a = np.array([1, 2, 3, 4])

# 2D array (matrix)
b = np.array([[1,2],[3,4]])

# Built‑in arrays
zeros = np.zeros((3,4)) # 3x4 array of zeros
ones = np.ones((2,3)) # 2x3 array of ones
range_arr = np.arange(0, 10, 2) # [0,2,4,6,8]
linspace = np.linspace(0, 1, 5) # [0, 0.25, 0.5, 0.75, 1]

Array Attributes

arr = np.array([[1,2,3],[4,5,6]])
print(arr.shape) # (2,3) – rows, columns
print(arr.ndim) # 2 – number of dimensions
print(arr.size) # 6 – total elements
print(arr.dtype) # int64 – data type

Why NumPy for AI?

  • Images are stored as 3D arrays (height × width × channels).
  • Neural network weights and biases are arrays.
  • Batch processing of data uses arrays.
  • Vectorized operations are much faster than Python loops.


Two Minute Drill
  • NumPy arrays are homogeneous and efficient.
  • Create from list: np.array().
  • Use np.zeros(), np.ones(), np.arange(), np.linspace().
  • Attributes: shape, ndim, size, dtype.

Need more clarification?

Drop us an email at career@quipoinfotech.com