/scientific-agent-skills:numpy-low-levelfrom scientific-agent-skills
Advanced NumPy skill for internal memory management, stride manipulation, structured arrays, and C/Cython interfacing. Covers zero-copy operations and SIMD vectorization principles.
Ships in scientific-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
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.
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".
Strides define how many bytes to skip in memory to get to the next element in each dimension. Manipulating strides allows you to "cheat" and create virtual views of data.
import numpy as np
arr = np.zeros((100, 100))
print(arr.flags) # Check contiguity and ownership
print(arr.strides) # bytes to step in each axis
print(arr.__array_interface__['data']) # Memory pointer address
arr.base is None to verify if an array owns its memory or is just a view.out argument to prevent creating a new temporary array.arr[[1, 3, 5]]) always creates a copy, unlike basic slicing.from numpy.lib.stride_tricks import as_strided
def sliding_window_1d(arr, window_size):
"""Creates a virtual 2D view of a 1D array for rolling stats."""
itemsize = arr.itemsize
shape = (arr.size - window_size + 1, window_size)
strides = (itemsize, itemsize)
return as_strided(arr, shape=shape, strides=strides)
# Result is a 2D array where each row is a window,
# but it uses NO additional memory.
# Define a record type: Name (32 chars), Age (int), Salary (float)
dtype = np.dtype([('name', 'S32'), ('age', 'i4'), ('salary', 'f8')])
data = np.array([('Alice', 25, 50000), ('Bob', 30, 60000)], dtype=dtype)
# Access by field name (Fast, vectorized)
print(data['salary'].mean())
import ctypes
# Get raw pointer to data
ptr = arr.ctypes.data_as(ctypes.POINTER(ctypes.c_double))
# This pointer can be passed to a C/C++ library
# for direct manipulation of the NumPy buffer.
# ❌ SLOW: Creates 3 temporary arrays
# res = (a * b) + c
# ✅ FAST: Reuse memory
np.multiply(a, b, out=a) # a now holds a*b
np.add(a, c, out=a) # a now holds (a*b)+c
# Create an array that stays on disk, reading only what's needed
huge_data = np.memmap('data.bin', dtype='float32', mode='w+', shape=(10000, 10000))
If you broadcast a small array across a large one, NumPy doesn't copy the small one; it just sets the stride to 0.
# strides of a (10, 1) array broadcasted to (10, 100):
# (8, 0) -> It keeps reading the same memory for the second axis!
Scientific data from old instruments might be Big-Endian.
# Convert in-place without copying
raw_data = np.frombuffer(buffer, dtype='>f4').view('<f4')
NumPy Low-Level is about removing abstractions. By mastering strides and the array interface, you turn Python into a thin wrapper over raw memory, enabling "impossible" data manipulations at hardware speeds.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub tondevrel/scientific-agent-skills --plugin scientific-agent-skills70 skills in this plugin
/aseAtomic Simulation Environment - a set of tools for setting up, manipulating, running, visualizing, and analyzing atomistic simulations. Acts as a universal interface between Python and numerous quantum chemical and molecular dynamics codes. Use for building atomic structures, geometry optimization, molecular dynamics simulations, transition state searches (NEB), file format conversion (CIF, XYZ, POSCAR, PDB), electronic property calculations (DOS, band structures), and automating simulation workflows with DFT/MD codes like VASP, GPAW, Quantum ESPRESSO, LAMMPS./astropyThe core library for Astronomy and Astrophysics in Python. Provides data structures for coordinates, time, units, FITS files, and cosmological models. Essential for observational data reduction and theoretical astrophysics. Use when working with astronomical coordinates (RA/Dec), physical units, FITS files, time scales, WCS, cosmology, or astronomical tables./biopythonComprehensive guide for Biopython - the premier Python library for computational biology and bioinformatics. Use for DNA/RNA/protein sequence analysis, file I/O (FASTA, FASTQ, GenBank, PDB), sequence alignment, BLAST searches, phylogenetic analysis, structure analysis, and NCBI database access./chempyA Python package useful for chemistry (mainly physical/analytical/inorganic chemistry). Features include balancing chemical reactions, chemical kinetics (ODE integration), chemical equilibria, ionic strength calculations, and unit handling. Use when working with chemical equations, reaction balancing, kinetic modeling, equilibrium calculations, speciation, pH calculations, ionic strength, activity coefficients, or chemical formula parsing./cobrapyConstraints-Based Reconstruction and Analysis for Python. Used for modeling large-scale metabolic networks in microorganisms./daskA flexible library for parallel computing in Python. It scales Python libraries like NumPy, pandas, and scikit-learn to multi-core systems or distributed clusters. Features lazy evaluation and task scheduling for data that exceeds RAM capacity. Use for out-of-core computing, parallel processing, distributed computing, large-scale data analysis, dask.array, dask.dataframe, dask.delayed, dask.bag, task scheduling, lazy evaluation, and scaling beyond memory limits.Other plugins' skills for the same job