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 1mo 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 1mo 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. 1mo 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 (14 stars, last pushed 4mo 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

Other skills, from other repositories

python-backend-expert

This skill should be used when the user is writing, reviewing, debugging, or architecting Python backend code using Litestar or FastAPI with SQLAlchemy or Advanced Alchemy. Provides expert critique covering SOLID principles, hexagonal architecture, repository/service patterns, dependency injection, async correctness…

mathisk2095/jko-claude-plugins · 183 tokens

backend-development

Use when building or structuring a Python backend on FastAPI + SQLAlchemy 2.0 (async) + Alembic + Pydantic v2. Provides the opinionated project layout, the standard kit (auth, async jobs, caching, storage, observability), and best practices.

martian56/claude-engineer · 63 tokens

odoo-python

Use when writing or reviewing any Python in an Odoo module — models, computes, overrides, controllers, wizards. Carries PSAE review-derived principles for ORM correctness, performance, style, and security, plus references for exact patterns. Invoke before writing logic in models/, controllers/, or wizard/.

omas-odoo/odoo-superpowers · 64 tokens

odoo-python

Use when writing or reviewing any Python in an Odoo module — models, computes, overrides, controllers, wizards. Carries PSAE review-derived principles for ORM correctness, performance, style, and security, plus references for exact patterns. Invoke before writing logic in models/, controllers/, or wizard/.

assoumaaa/odoo-superpowers · 64 tokens

astropy

Core Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.

K-Dense-AI/scientific-agent-skills · 56 tokens

matlab

Builds, reviews, migrates, and plans MATLAB or GNU Octave numerical workflows. Use for arrays, tabular/time data, tests, projects, graphics, MAT files, and explicit Python interoperability.

K-Dense-AI/scientific-agent-skills · 44 tokens