policyengine-vectorization

Replace scalar branching with NumPy array operations in PolicyEngine microsimulations.

31|6|Updated Oct 19, 2025
One-click install
npx skills add https://github.com/PolicyEngine/policyengine-claude --skill policyengine-vectorization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: policyengine-vectorization
Source: https://github.com/PolicyEngine/policyengine-claude/tree/main/skills/technical-patterns/policyengine-vectorization-skill
Command: npx skills add https://github.com/PolicyEngine/policyengine-claude --skill policyengine-vectorization

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill emphasizes vectorization to avoid scalar logic when processing multiple households simultaneously with NumPy arrays.

Core Features & Use Cases

  • Vectorized conditions: Replace if-elif with where() and select().
  • Boolean operations: Use &, |, ~ for arrays.
  • Clipping and lookups: Use clip and vectorized lookups for performance.

Quick Start

Convert a scalar if-else block into a where() call to operate on arrays.

Frequently Asked Questions about policyengine-vectorization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I vectorize policy computations to process multiple households in parallel?

Vectorization replaces scalar if-elif-else logic with NumPy array operations like where() and select() to process thousands of households simultaneously. This eliminates Python branching and applies conditions directly across array data, dramatically improving performance in microsimulations.

When should I use NumPy where() and select() instead of if-elif statements?

Use where() and select() when processing array data from multiple entities. These NumPy functions apply conditions across entire arrays without scalar branching, preventing performance bottlenecks that occur when looping through individual records in PolicyEngine microsimulations.

Can I use boolean operations and clipping with NumPy arrays in policy formulas?

Yes. Boolean operations (&, |, ~) and clip() work on entire arrays simultaneously, replacing scalar conditionals. This vectorized approach maintains performance when applying bounds and lookups across thousands of household records.

What's the performance difference between scalar if-else and vectorized NumPy operations?

Vectorized operations process entire arrays in a single operation, while scalar if-else requires iterating through each record individually. For PolicyEngine microsimulations handling thousands of households, vectorization eliminates loop overhead and leverages NumPy's optimized C-level implementations.

How do I convert existing scalar policy logic into vectorized array operations?

Replace each if-elif block with where() for binary conditions or select() for multiple branches, operating on boolean masks across your entire array. Then apply clip() for value bounds and vectorized lookups for table references instead of scalar dictionary access.