326-numpy

Enforce vectorized, dtype-explicit, broadcasting-safe NumPy workflows with NaN-safe validation.

Updated May 21, 2026
One-click install
npx skills add https://github.com/ulf1/trading-regime --skill 326-numpy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: 326-numpy
Source: https://github.com/ulf1/trading-regime/tree/main/.agent/skills/326-numpy
Command: npx skills add https://github.com/ulf1/trading-regime --skill 326-numpy

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes assets (resource) components.

What problem does it solve?

Prevents slow, buggy, or numerically unstable NumPy code by enforcing idiomatic, memory-efficient patterns and robust validation practices.

Core Features & Use Cases

  • Zero-copy performance discipline: Prefer views, broadcasting with dimension expansion (np.newaxis/None), and avoid accidental copies from fancy/boolean indexing.
  • Type- and shape-safety: Enforce explicit dtypes and shape normalization for reliable downstream model/estimator compatibility.
  • Numerical hygiene & testing: Detect NaNs/Infs correctly and validate with numpy.testing tolerances (assert_allclose) rather than fragile equality.
  • Performance primitives: Use argpartition for top-k selection, out= reuse patterns, and C-level/GIL-releasing operations (e.g., FFT) to enable safe multithreading.

Quick Start

Use the 326-numpy skill to refactor your NumPy code for vectorization, explicit dtypes, and NaN-safe validation while ensuring top-k selection uses argpartition instead of argsort.

Frequently Asked Questions about 326-numpy

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

FAQPage Schema
How do I avoid accidental data copies when slicing and reshaping NumPy arrays?

To prevent slow NumPy array copies, enforce zero-copy slicing by using views, broadcasting with np.newaxis, and avoiding fancy or boolean indexing triggers. This approach maintains memory efficiency and improves computation speed across array reshaping operations.

What is the best way to find the top-k elements in a NumPy array without sorting everything?

Finding the top-k elements in NumPy is best done using argpartition instead of argsort. This performance primitive partially sorts the array, reducing computational overhead and significantly speeding up top-k selection in ML data pipelines.

Why are my NumPy array comparisons failing when checking floating point computation results?

NumPy array comparisons fail due to floating point precision limits, requiring numerical hygiene to validate correctly. Use numpy.testing tolerances like assert_allclose instead of fragile equality to ensure reliable results across shapes and edge cases.

How do I prevent NumPy broadcasting errors when operating on mismatched array shapes?

Preventing NumPy broadcasting errors requires explicit dtype control and shape normalization before operations. Apply dimension expansion using np.newaxis to align array shapes, ensuring broadcasting-safe workflows for reliable downstream model compatibility.

Can I use NumPy FFT operations in parallel multithreaded data pipelines?

Yes, NumPy FFT operations can be used in parallel multithreaded data pipelines by leveraging C-level and GIL-releasing operations. This performance primitive enables safe multithreading and out= array reuse patterns to optimize numeric computations.

How do I correctly detect NaNs and Infs to maintain numerical hygiene in NumPy?

To correctly detect NaNs and Infs in NumPy and maintain numerical hygiene, apply NaN-safe operations during array creation and feature preparation. This prevents numerical instability from propagating through vectorized computations and downstream estimators.