Agent skill
numpy-linalg
Install this agent skill to your Project
npx add-skill https://github.com/cuba6112/skillfactory/tree/main/skills/numpy-linalg
SKILL.md
Overview
NumPy's linalg module provides high-performance implementations for standard linear algebra routines. It leverages optimized backends (like BLAS/LAPACK) for operations such as Singular Value Decomposition (SVD), batch equation solving, and least-squares optimization.
When to Use
- Solving systems of linear equations ($Ax = b$).
- Dimensionality reduction or matrix reconstruction using SVD.
- Optimizing chains of matrix multiplications to reduce FLOPs.
- Finding best-fit solutions for overdetermined systems.
Decision Tree
- Multiplying two matrices?
- Use the
@operator (modern standard).
- Use the
- Multiplying 3+ matrices?
- Use
np.linalg.multi_dotto optimize multiplication order.
- Use
- Is the matrix square and full-rank?
- Yes: Use
np.linalg.solve. - No: Use
np.linalg.lstsqfor a best-fit solution.
- Yes: Use
Workflows
-
Solving Multiple Linear Systems in Batch
- Organize coefficient matrices into a stack of shape (K, M, M).
- Organize ordinate values into a stack of shape (K, M).
- Call
np.linalg.solve(a, b)to compute all solutions simultaneously.
-
Rank-Reduced Reconstruction via SVD
- Perform Singular Value Decomposition using
np.linalg.svd(a, full_matrices=False). - Set small singular values in 's' to zero to perform noise reduction.
- Reconstruct the matrix using
(u * s) @ vh.
- Perform Singular Value Decomposition using
-
Least Squares Fitting for Overdetermined Systems
- Construct the matrix 'A' of variables and vector 'b' of results.
- Use
np.linalg.lstsq(A, b)to find the solution that minimizes the Euclidean 2-norm. - Retrieve the coefficients and residuals from the returned tuple.
Non-Obvious Insights
- Modern Operator: The
@operator is preferred overdot()for 2D matrix products for readability and intent. - Multi-Dot Optimization:
multi_dotuses dynamic programming to find the optimal parenthesization of matrix products, which can significantly speed up calculations with varying matrix sizes. - Batch Processing: Most
linalgfunctions support "stacked" arrays, processing multiple independent problems in leading dimensions automatically.
Evidence
- "The @ operator... is preferable to other methods when computing the matrix product between 2d arrays." Source
- "a must be square and of full-rank... if either is not true, use lstsq for the least-squares best “solution”." Source
Scripts
scripts/numpy-linalg_tool.py: Demonstrates SVD reconstruction and batch solving.scripts/numpy-linalg_tool.js: Simulated vector normalization logic.
Dependencies
numpy(Python)
References
- references/README.md
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
prompt-engineering
Comprehensive prompt engineering techniques for Claude models. Use this skill when crafting, optimizing, or debugging prompts for Claude API, Claude Code, or any Claude-powered application. Covers system prompts, role prompting, multishot examples, chain of thought, XML structuring, long context handling, extended thinking, prompt chaining, Claude 4.x-specific best practices, and agentic orchestration including subagents, agent loops, skills, MCP integration, and multi-agent workflows.
adk-rag-agent
Build RAG (Retrieval-Augmented Generation) agents with Google ADK and Vertex AI RAG Engine. Use when implementing document Q&A, knowledge base search, or citation-backed responses. Covers VertexAiRagRetrieval tool, corpus setup, and citation formatting.
headless-cli-agents
Build agentic systems using Claude CLI in headless mode or the Claude Agent SDK. Use when building automation pipelines, CI/CD integrations, multi-agent orchestration, or programmatic Claude interactions. Covers CLI flags (-p, --output-format), session management (--resume, --continue), Python SDK (claude-agent-sdk), custom tools, and agent loop patterns.
notion-knowledge-capture
Capture conversations and decisions into structured Notion pages; use when turning chats/notes into wiki entries, how-tos, decisions, or FAQs with proper linking.
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
gh-fix-ci
Inspect GitHub PR checks with gh, pull failing GitHub Actions logs, summarize failure context, then create a fix plan and implement after user approval. Use when a user asks to debug or fix failing PR CI/CD checks on GitHub Actions and wants a plan + code changes; for external checks (e.g., Buildkite), only report the details URL and mark them out of scope.
Didn't find tool you were looking for?