NumPy and Automation Scripts

Harry · 14 Sep 2026 · 2 views
Advertisement
Advertisement

NumPy for Fast Numeric Work

NumPy provides the ndarray, a fast multi-dimensional array that powers pandas and most of the scientific stack.

import numpy as np

arr = np.array([1, 2, 3, 4])
print(arr * 2)          # [2 4 6 8]  vectorised

matrix = np.ones((2, 3), dtype=int)
print(matrix)
print(arr.sum(), arr.mean(), arr.max())

Renaming Files in Bulk (Automation)

import os

folder = "screenshots"
for idx, fname in enumerate(os.listdir(folder)):
    if fname.endswith(".png"):
        new_name = f"lesson_{idx:03d}.png"
        os.rename(os.path.join(folder, fname), os.path.join(folder, new_name))
        print(f"{fname} -> {new_name}")

Reading a CSV Without pandas (stdlib)

import csv

with open("data.csv", newline="") as f:
    rows = list(csv.DictReader(f))
    total = sum(float(r["amount"]) for r in rows)
print(total)

Key Points

  • NumPy vectorises maths: no explicit loops needed.
  • The standard library (os, csv, shutil) covers most automation.
  • Automation scripts are often the fastest Python win in a team.
Share this post:

Comments (0)

Please login or register to comment.