NumPy Quick Reference
=====================

IMPORT
  import numpy as np

ARRAY CREATION
  np.array([1, 2, 3])           From list
  np.zeros((3, 4))              3x4 zeros
  np.ones((3, 4))               3x4 ones
  np.arange(0, 10, 2)           [0, 2, 4, 6, 8]
  np.linspace(0, 1, 5)          5 evenly spaced [0,1]
  np.eye(3)                     3x3 identity matrix
  np.random.randint(0, 256, 100)  Random integers
  np.frombuffer(data, dtype=np.uint8)  From bytes

ARRAY INFO
  a.shape                       Dimensions
  a.dtype                       Data type
  a.size                        Total elements
  a.ndim                        Number of dimensions

OPERATIONS
  a + b                         Element-wise add
  a * b                         Element-wise multiply
  a @ b / np.dot(a, b)          Matrix multiply
  a.T                           Transpose
  np.linalg.inv(a)              Inverse
  np.linalg.det(a)              Determinant
  np.linalg.solve(A, b)         Solve Ax = b

TYPE CONVERSION
  a.astype(np.uint8)            Convert type
  a.tobytes()                   Array → bytes
  np.frombuffer(b, np.uint8)    Bytes → array

INDEXING
  a[0]                          First element
  a[-1]                         Last element
  a[1:5]                        Slice
  a[a > 5]                      Boolean indexing
  a.reshape(3, 4)               Reshape

USEFUL FOR CTF
  # XOR arrays
  result = np.bitwise_xor(a, b)

  # Byte frequency analysis
  data = np.frombuffer(file_bytes, dtype=np.uint8)
  unique, counts = np.unique(data, return_counts=True)

  # Image as array
  from PIL import Image
  img_array = np.array(Image.open("img.png"))
  # img_array.shape → (height, width, channels)

  # Matrix operations for crypto
  M = np.array([[1,2],[3,4]], dtype=np.int64)
  result = np.linalg.matrix_power(M, n)
