Agent skill
numpy-masked
Install this agent skill to your Project
npx add-skill https://github.com/cuba6112/skillfactory/tree/main/skills/numpy-masked
SKILL.md
Overview
The numpy.ma module provides masked arrays, which couple a data array with a boolean mask. Masked elements are ignored in operations like mean(), sum(), and log(), making them ideal for datasets where certain entries should be excluded without deleting them and losing shape information.
When to Use
- Handling sensor data with "no-data" values (e.g., -999).
- Performing statistics on arrays containing NaNs or Infs where you want the invalid values automatically excluded.
- Protecting specific data points from modification during processing using a "hard mask."
- Exporting data where missing values must be filled with a specific constant.
Decision Tree
- Do you need to keep the original array shape while ignoring certain values?
- Use
ma.masked_array.
- Use
- Are you performing math on risky values (e.g., negative numbers in log)?
- Use
ma.masked_invalid(arr)orma.masked_less(arr, 0).
- Use
- Want to extract only valid data for another tool?
- Use the
.compressed()method to get a 1D array of valid values.
- Use the
Workflows
-
Calculating Stats on Tainted Data
- Create a masked array from raw data using
ma.masked_values(data, -999). - Perform a
.mean()calculation. - Observe that the result only reflects valid, unmasked data points.
- Create a masked array from raw data using
-
Filling Missing Values for Export
- Identify a masked array with gaps.
- Call
.filled(fill_value=0)to create a standard ndarray. - Save the filled array to a CSV or binary file.
-
Domain-Safe Vectorized Operations
- Use
ma.masked_invalid(arr)to mask NaNs and Infs. - Apply a mathematical function (e.g.,
ma.sqrt). - Resulting array will have masks wherever the operation was invalid (e.g., square root of negative).
- Use
Non-Obvious Insights
- Hard Masking: If a masked array has a "hard mask," assigning a value to a masked entry will silently fail; it remains masked. This is a safety feature for protecting outlier exclusions.
- Assignment Masking: Assigning the constant
ma.maskedto an array element automatically updates the internal mask toTruefor that position. - Compression Side-Effect: Calling
.compressed()returns a 1D array, which destroys the original dimensionality (e.g., a 2D masked array becomes 1D).
Evidence
- "The package ensures that masked entries are not used in computations." Source
- "Unary and binary functions that have a validity domain (such as log or divide) return the masked constant whenever the input is masked or falls outside the validity domain." Source
Scripts
scripts/numpy-masked_tool.py: Routines for masked stats and domain-safe sqrt.scripts/numpy-masked_tool.js: Simulated boolean mask filtering.
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?