numpy-low-level
Installation
SKILL.md
NumPy - Low-Level Optimization & Memory
At high volumes, standard NumPy operations can still be slow due to unnecessary memory allocations. This guide covers how to manipulate the internal representation of arrays to achieve C-level performance without leaving Python.
When to Use
- Implementing sliding window algorithms (convolutions) without extra memory.
- Interfacing Python with C, C++, or Fortran code via pointers.
- Working with complex, heterogeneous data structures (Structured Arrays).
- Optimizing memory-constrained systems via Memory Mapping (memmap).
- Debugging performance issues related to "Memory Layout" (C-style vs Fortran-style).
Core Principles
1. The Metadata vs. Data Split
A NumPy array is a small Header (shape, dtype, strides) pointing to a large Data Buffer. Many operations (like .T, reshape, slice) only change the Header. This is "Zero-Copy".