numpy-best-practices
Skill275 starsChanged 52 days agoApache-2.0View on GitHub
Best practices for NumPy array programming, numerical computing, and performance optimization in Python
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- ZeroTokenClaw/agents-skillsedited, first seen Sep 21, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- ZeroTokenClaw/agents-skills★ 199% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository264 other files it gives its agents.
- accessibility-a11ySkill
- alpine-jsSkill
- analytics-data-analysisSkill
- android-developmentSkill
- angular-developmentSkill
- angularSkill
- anime-jsSkill
- anthropic-claude-developmentSkill
- api-developmentSkill
- apollo-graphqlSkill
- aspnet-coreSkill
- astroSkill
- auth0-authenticationSkill
- autogen-developmentSkill
- automl-hyperparameter-optimizationSkill
- aws-developmentSkill
- azureSkill
- backend-developmentSkill
- bash-scriptingSkill
- beautifulsoup-parsingSkill
- bitbucket-workflowSkill
- blazorSkill
- blender-python-addonSkill
- blockchainSkill
- bootstrapSkill
- business-central-developmentSkill
- cheerio-parsingSkill
- chrome-extension-developmentSkill
- ci-cd-best-practicesSkill
- clean-architectureSkill
- clean-codeSkill
- clerk-authenticationSkill
- cloudflare-developmentSkill
- computer-vision-opencvSkill
- convexSkill
- cppSkill
- c-sharpSkill
- cssSkill
- cypressSkill
- data-analysis-jupyterSkill
- data-analystSkill
- data-jupyter-pythonSkill
- deep-learning-pythonSkill
- deep-learning-pytorchSkill
- deep-learningSkill
- deno-typescriptSkill
- design-systemsSkill
- devopsSkill
- django-pythonSkill
- django-rest-api-developmentSkill
- dockerSkill
- dotnetSkill
- drizzle-ormSkill
- drupal-developmentSkill
- elasticsearch-best-practicesSkill
- electron-developmentSkill
- elixirSkill
- embedded-stm32Skill
- esbuild-bundlerSkill
- ethereumSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
34 rules. About 0 are common, 10 are distinctive, and 24 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
24
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Write concise, technical Python code with accurate NumPy examples
- Distinctive: line 16
Prefer vectorized operations over explicit loops for performance
- Very specific: line 17
Use descriptive variable names reflecting data content (e.g., weights, gradients, input_array)
- Distinctive: line 18
Follow PEP 8 style guidelines for Python code
- Distinctive: line 19
Use functional programming patterns when appropriate
- Very specific: line 23
Use appropriate array creation functions: np.array(), np.zeros(), np.ones(), np.empty(), np.arange(), np.linspace()
- Very specific: line 24
Prefer np.zeros() or np.empty() for pre-allocation when array size is known
- Very specific: line 25
Use np.concatenate(), np.vstack(), np.hstack() for combining arrays
- Distinctive: line 30
Use advanced indexing with boolean arrays for conditional selection
- Distinctive: line 31
Prefer views over copies when possible to save memory
- Very specific: line 32
Use np.where() for conditional element selection
- Very specific: line 38
Use np.float32 for memory-efficient computations when full precision is not needed
- Very specific: line 40
Use np.asarray() for type conversion without unnecessary copies
- Distinctive: line 46
Always prefer vectorized operations over Python loops
- Distinctive: line 47
Use NumPy universal functions (ufuncs) for element-wise operations
- Very specific: line 49
Use np.dot() or @ operator for matrix multiplication
- Very specific: line 53
Use np.ndarray.flags to check memory layout (C-contiguous vs Fortran-contiguous)
- Very specific: line 54
Prefer in-place operations with out parameter when possible
- Very specific: line 55
Use memory-mapped arrays (np.memmap) for large datasets
- Very specific: line 60
Use np.sum(), np.mean(), np.std() with axis parameter for aggregations
- Very specific: line 62
Use np.searchsorted() for efficient sorted array operations
- Distinctive: line 67
Use assertions for dimension checking with informative messages
- Very specific: line 69
Use np.errstate() context manager for controlling floating-point error handling
- Very specific: line 73
Use np.random.default_rng() for modern random number generation
- Very specific: line 75
Prefer the new Generator API over legacy np.random functions
- Very specific: line 76
Use appropriate distributions: rng.normal(), rng.uniform(), rng.choice()
- Very specific: line 80
Use np.linalg for linear algebra operations
- Very specific: line 82
Use np.linalg.eig(), np.linalg.svd() for decompositions
- Very specific: line 83
Check matrix condition with np.linalg.cond() before inversion
- Very specific: line 87
Write unit tests using pytest with np.testing assertions
- Very specific: line 88
Use np.testing.assert_array_equal() for exact comparisons
- Very specific: line 89
Use np.testing.assert_array_almost_equal() for floating-point comparisons
- Very specific: line 95
Use snake_case for variables and functions
- Distinctive: line 96
Document array shapes in docstrings
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
NumPy Best Practices
Expert guidelines for NumPy development, focusing on array programming, numerical computing, and performance optimization.
Code Style and Structure
- Write concise, technical Python code with accurate NumPy examples
- Prefer vectorized operations over explicit loops for performance
- Use descriptive variable names reflecting data content (e.g.,
weights,gradients,input_array) - Follow PEP 8 style guidelines for Python code
- Use functional programming patterns when appropriate
Array Creation and Manipulation
- Use appropriate array creation functions:
np.array(),np.zeros(),np.ones(),np.empty(),np.arange(),np.linspace() - Prefer
np.zeros()ornp.empty()for pre-allocation when array size is known - Use
np.concatenate(),np.vstack(),np.hstack()for combining arrays - Leverage broadcasting for operations on arrays with different shapes
Indexing and Slicing
- Use advanced indexing with boolean arrays for conditional selection
- Prefer views over copies when possible to save memory
- Use
np.where()for conditional element selection - Understand the difference between fancy indexing (creates copy) and basic slicing (creates view)
Data Types
- Specify appropriate data types explicitly using
dtypeparameter - Use
np.float32for memory-efficient computations when full precision is not needed - Be aware of integer overflow with fixed-size integer types
- Use
np.asarray()for type conversion without unnecessary copies
Performance Optimization
Vectorization
- Always prefer vectorized operations over Python loops
- Use NumPy universal functions (ufuncs) for element-wise operations
- Leverage
np.einsum()for complex tensor operations - Use
np.dot()or@operator for matrix multiplication
Memory Management
- Use
np.ndarray.flagsto check memory layout (C-contiguous vs Fortran-contiguous) - Prefer in-place operations with
outparameter when possible - Use memory-mapped arrays (
np.memmap) for large datasets - Be mindful of array copies vs views
Computation Efficiency
- Use
np.sum(),np.mean(),np.std()withaxisparameter for aggregations - Leverage
np.cumsum(),np.cumprod()for cumulative operations - Use
np.searchsorted()for efficient sorted array operations
Error Handling and Validation
- Validate input shapes and data types before computations
- Use assertions for dimension checking with informative messages
- Handle NaN and Inf values appropriately with
np.isnan(),np.isinf() - Use
np.errstate()context manager for controlling floating-point error handling
Random Number Generation
- Use
np.random.default_rng()for modern random number generation - Set seeds for reproducibility:
rng = np.random.default_rng(seed=42) - Prefer the new Generator API over legacy
np.randomfunctions - Use appropriate distributions:
rng.normal(),rng.uniform(),rng.choice()
Linear Algebra
- Use
np.linalgfor linear algebra operations - Leverage
np.linalg.solve()instead of computing inverse for linear systems - Use
np.linalg.eig(),np.linalg.svd()for decompositions - Check matrix condition with
np.linalg.cond()before inversion
Testing and Documentation
- Write unit tests using
pytestwithnp.testingassertions - Use
np.testing.assert_array_equal()for exact comparisons - Use
np.testing.assert_array_almost_equal()for floating-point comparisons - Include comprehensive docstrings following NumPy docstring format
Key Conventions
- Import as
import numpy as np - Use
snake_casefor variables and functions - Document array shapes in docstrings
- Profile code with
%timeitto identify bottlenecks
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

