Agent skill

numpy-ufuncs

Stars 0
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/cuba6112/skillfactory/tree/main/skills/numpy-ufuncs

SKILL.md

Overview

Universal functions (ufuncs) are the engine behind NumPy's vectorization. They perform element-wise operations on ndarrays, supporting broadcasting, type casting, and efficient internal loops. They also provide methods for cumulative operations (accumulate) and reductions (reduce).

When to Use

  • Performing high-speed mathematical operations across entire arrays.
  • Reducing memory overhead using in-place operations (out parameter).
  • Creating custom mathematical operations that broadcast like native NumPy functions.
  • Applying operations conditionally using the where parameter.

Decision Tree

  1. Need to perform an operation without creating a new array?
    • Pass the destination array to the out parameter.
  2. Have a custom Python function to apply to an array?
    • Use np.frompyfunc for broadcasting (returns PyObjects).
    • Use np.vectorize for API convenience (not performance).
  3. Performing a reduction on small integers?
    • Check for overflow; small types (int8) will silently wrap.

Workflows

  1. Memory-Efficient In-Place Operation

    • Create arrays A and B.
    • Execute np.multiply(A, B, out=A) to perform the multiplication.
    • Observe that A is updated without allocating a new result array.
  2. Conditional Vectorized Calculation

    • Define a calculation (e.g., np.log).
    • Define a condition mask where values are valid (e.g., x > 0).
    • Call np.log(x, out=result, where=mask) to avoid errors or domain warnings.
  3. Creating a Custom Broad-Castable Function

    • Define a Python function that takes scalar inputs.
    • Wrap it with np.frompyfunc(func, nin, nout).
    • Apply the new ufunc to multidimensional arrays to automatically trigger NumPy broadcasting.

Non-Obvious Insights

  • Vectorize is a Loop: np.vectorize is a convenience wrapper for a Python for-loop and does not provide C-level speed improvements.
  • Silent Wrapping: Reductions on data types with a small range (like int8) will wrap around (e.g., 127 + 1 = -128) silently instead of raising an error.
  • Out Uninitialized: If using the where parameter with out, elements where the condition is False remain uninitialized (they retain whatever was in the output array previously).

Evidence

  • "Note that the output is filled only in the places that the broadcast ‘where’ is True... elements not explicitly filled are left with their uninitialized values." Source
  • "The vectorize function is provided primarily for convenience, not for performance. The implementation is essentially a for loop." Source

Scripts

  • scripts/numpy-ufuncs_tool.py: Demonstrates in-place multiplication and custom ufunc creation.
  • scripts/numpy-ufuncs_tool.js: Simulated element-wise map function.

Dependencies

  • numpy (Python)

References

  • references/README.md

Expand your agent's capabilities with these related and highly-rated skills.

cuba6112/skillfactory

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.

0 0
Explore
cuba6112/skillfactory

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.

0 0
Explore
cuba6112/skillfactory

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.

0 0
Explore
cuba6112/skillfactory

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.

0 0
Explore
cuba6112/skillfactory

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).

0 0
Explore
cuba6112/skillfactory

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.

0 0
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results