numpy-vectorization-for-optimization

numpy-vectorization-for-optimization is a skill for Claude Code, Codex from hajibabaie/combinatorial-optimization-skills. It costs 125 tokens per session (10,543 once invoked), scanned B, original, MIT.

A guide to replacing slow Python loops in optimization programs with NumPy array operations. It covers batch calculations, broadcasting, distance tables, sorting, random-number generation, and memory use.

In plain words
What is it for?
Use it to speed up population-based optimization, batch fitness scoring, distance calculations, and other measured bottlenecks in scientific Python code.
Why use it?
It helps identify which loops actually slow a program down and rewrite those parts without changing the algorithm's result.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/hajibabaie/combinatorial-optimization-skills/numpy-vectorization-for-optimization
Any agent
npx skills add hajibabaie/combinatorial-optimization-skills --skill numpy-vectorization-for-optimization
Clone the repo
git clone --depth 1 https://github.com/hajibabaie/combinatorial-optimization-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for numpy-vectorization-for-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/hajibabaie/combinatorial-optimization-skills/numpy-vectorization-for-optimization.svg)](https://agentmods.dev/skills/hajibabaie/combinatorial-optimization-skills/numpy-vectorization-for-optimization)
Your own site
<a href="https://agentmods.dev/skills/hajibabaie/combinatorial-optimization-skills/numpy-vectorization-for-optimization"><img src="https://agentmods.dev/badge/skills/hajibabaie/combinatorial-optimization-skills/numpy-vectorization-for-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 125 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 10,543 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00125 $0.10543
Opus 5 $0.00063 $0.05271
Sonnet 5 $0.00025 $0.02109
Haiku 4.5 $0.00013 $0.01054

Measured 4d ago against content hash cdc100e930ea, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade B, and why

numpy-vectorization-for-optimization scanned grade B with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Strips warnings and disclaimersmediumAnti-refusal

Omitting safety caveats hides risk from the user and is a common jailbreak preamble.

around without any warning (NumPy fixed-width ints are modular). Promote to int64 or float64
skills/numpy-vectorization-for-optimization/SKILL.md · 787 lines

How it starts

The opening of the file, as written. The whole thing — 787 lines — stays where its author put it; the contents beside it link to each section on GitHub.

NumPy Vectorization for Optimization

You are an expert in high-performance scientific Python for combinatorial optimization. This skill covers turning loop-based metaheuristic code into vectorized NumPy: population-level operations, batch fitness evaluation, distance matrices, broadcasting, argsort/argpartition idioms, the default_rng Generator API, and memory layout — plus the profiling discipline that decides which loops are worth removing. Use the pattern catalog below to deliver 10-1000x constant-factor speedups without changing what the algorithm computes.

Initial Assessment

Establish these facts before rewriting any loop:

  • Profile evidence. Ask for (or produce) a cProfile or timing breakdown. Never vectorize a loop that consumes 3% of runtime; Amdahl's law caps the whole-run gain at 1.03x.
  • Algorithm class. Population methods (GA, DE, PSO, EDA) vectorize naturally: one array axis is the population. Trajectory methods (SA, tabu, ILS) have sequentially dependent iterations; only their inner evaluations and neighborhood scans vectorize.
  • Loop inventory. Classify every hot loop: over individuals, over genes within an individual, over parent pairs, over neighborhood moves, over generations, over restarts. Each class has a different replacement pattern (see the decision table below).
  • Array sizes. NumPy pays a fixed ~1 µs dispatch cost per call. Arrays under a few hundred elements rarely amortize it; a (pop_size, n) batch almost always does.
  • Objective structure. Can the objective be written as gathers (fancy indexing), elementwise ops, reductions, and matrix products? Sums of local terms vectorize; recursions with data-dependent state (e.g., makespan propagation) resist and may need a JIT instead.
  • Branchiness. Data-dependent if/else per element converts to masks and np.where; deep nested control flow may produce unreadable mask algebra — consider Numba for those kernels.
  • Memory headroom. Broadcasting materializes temporaries: (n, n, d) for pairwise differences, (p, n, n) for batched matrix gathers. Check RAM before promising speed.
  • dtype and value ranges. Integer products overflow silently in NumPy fixed-width ints; float32 halves bandwidth but costs precision. Decide dtypes up front.
  • Reproducibility contract. Vectorizing changes the RNG draw order, so results differ from the loop version even with the same seed. Agree on equivalence: bit-identical (rarely possible), numerically identical given the same inputs, or statistically equivalent.
  • Dependency policy. NumPy only, or are SciPy (cdist), Numba, and threadpoolctl allowed?
  • Hardware and BLAS. Core count and BLAS backend (OpenBLAS/MKL) matter for @-heavy code, and BLAS threading interacts badly with multiprocessing workers.
  • Target throughput. Evaluations/second needed for the experiment budget. Stop optimizing when the budget fits; refactoring time is also research time.

Read the full file on GitHub · 787 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 787 lines · 125 tokens per session scan B cdc100e930ea

Subscribe to this mod's changes

numpy-vectorization-for-optimization is a skill published in the GitHub repository hajibabaie/combinatorial-optimization-skills (7 stars, last pushed 2mo ago), licensed MIT. It adds 125 tokens to every session and 10,543 once invoked, about $0.0006 per session on Opus 5. A static security scan graded it B with 1 finding (strips warnings and disclaimers). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

esp32-expert

This skill should be used for ESP32-specific hardware and runtime work in ESP-IDF, Arduino-ESP32, or PlatformIO projects: target/build detection, FreeRTOS tasks and ISRs, memory/DMA, peripherals, power, networking/security, OTA, crash diagnosis, and unattended reliability. Trigger on "debug this ESP32 crash", "review…

johnkozaris/jko-claude-plugins · 137 tokens

janitor-value

Show whether each skill is earning its context-window cost — combined tokens-used view sorted by waste. Use when the user asks 'are my skills worth it', 'what's my context budget', 'which skills are dead weight', or wants to audit skill value, token cost, or usage. Trigger with '/janitor-value'.

khendzel/skills-janitor · 69 tokens

ucai-patterns

Use when the user asks about Claude Code best practices, how to write agents, how to use hooks, how to manage context, or how to work effectively with Claude Code's native systems.

Joncik91/ucai · 42 tokens

code-reviewer

Code review knowledge base: quality, security (OWASP Top 10), error-handling, performance, and test-coverage checklists with severity-ranked output format. Use when reviewing code changes, PRs, or before commits. Loaded automatically by the code-reviewer agent.

claude-world/director-mode-lite · 59 tokens

evolving-status

View Self-Evolving Loop session status, history, and memory metrics.

claude-world/director-mode-lite · 17 tokens

orient

Use when user invokes /orient with a topic keyword, entity type, project name, time qualifier, or combination. Also triggers on "what do we know about X", "remind me about X", "where did we leave off on X". Provides targeted context loading — searches the MCP Memory Server graph, knowledge files, journal entries, and…

harnessprotocol/harness-kit · 80 tokens