numpy-vectorization-for-optimization

numpy-vectorization-for-optimization is a skill for Claude Code 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 Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: positional $N argument.

Part of the combinatorial-optimization plugin — 76 skills shipped together

Good fit Use it to speed up population-based optimization, batch fitness scoring, distance calculations, and other measured bottlenecks in scientific Python code.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/hajibabaie/combinatorial-optimization-skills/numpy-vectorization-for-optimization
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.

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.

Or install combinatorial-optimization, the plugin that ships this one along with the rest of its 76 skills.

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/github.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/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for numpy-vectorization-for-optimization

Your own site · 80×15
<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="Reviewed on agentmods" width="80" 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. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00125 $0.10543
Opus 5.5 $0.00050 $0.04217
Sonnet 5.5 $0.00025 $0.02109
Haiku 4.5 $0.00013 $0.01054

Measured 3mo ago against content hash cdc100e930ea, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 3mo 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. 3mo 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 (23 stars, last pushed 5mo ago), licensed MIT. It adds 125 tokens to every session and 10,543 once invoked, about $0.0005 per session on Opus 5.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

numpy-vectorization-for-optimization compared with skills from other repositories

numpy-vectorization-for-optimization next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
numpy-vectorization-for-optimizationhajibabaie/combinatorial-optimization-skillsSkill235mo agoMITB125Claude Code
python-backend-expertmathisk2095/jko-claude-pluginsSkill31mo agoMITA183Claude Code
backend-developmentmartian56/claude-engineerSkill155mo agoMITA63Claude Code
odoo-pythonomas-odoo/odoo-superpowersSkill15mo agononeA64Claude Code
odoo-pythonassoumaaa/odoo-superpowersSkill15mo agononeA64Claude Code
astropyK-Dense-AI/scientific-agent-skillsSkill59k3d agoMITA56Claude Code, Codex
matlabK-Dense-AI/scientific-agent-skillsSkill59k3d agoMITA44Claude Code