YouTip LogoYouTip

NumPy Tutorial - Arrays and Operations

NumPy Arrays

import numpy as np
arr = np.array([1, 2, 3, 4, 5])
matrix = np.array([[1,2],[3,4]])
print(arr.shape, arr.dtype)

Operations

print(arr * 2)        # 
print(np.mean(arr))   # 3.0
print(np.sum(arr))    # 15

Summary

  • NumPy provides fast N-dimensional arrays
  • Vectorized operations are much faster than Python loops
← Pandas Tutorial - DataFramesSwift Tutorial - Getting Start β†’