Iván

NumPy

开发编程v1.0.0
作者:Iván更新于 2026-05-11numpy@clawhub_ivangdavila/numpy
代码生成脚本工具

据 AlphaMoat 统计,截至 2026-09,NumPy 累计下载 1,657 次、获 0 个星标,在全部 5,078 个 AI 技能中排名第 4,669 位,在「开发编程」分类(577 个)中排名第 549 位。

累计安装
113
累计下载
1,657
星标
-
全站排名
#4,669
全站前 92% · 「开发编程」前 96%
平台累计安装累计下载星标评论
ClawHub ↗401,473--
SkillHub ↗1131,657-—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

内容包括数组形状与类型、轴操作、内置数学函数、视图与副本、数据整理和矩阵运算。技能说明计算在本地执行,但可能保存偏好和代码片段;只在用户明确同意后保存必要信息,并让本地记录可检查和删除。 初始化还建议写入共享主记忆;写入前须取得明确同意。

资料发布于 2026-10-29

可以用来做什么

  • 用数组运算替代逐项处理
  • 理解广播、轴和数据类型行为
  • 使用内置函数执行统计与线性代数操作

什么时候用

  • 需要在 Python 中执行数组或数值计算时
  • 需要检查广播、视图/副本或数据类型导致的结果差异时

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

解释如何用 NumPy 对数组执行逐元素运算;不要保存我的偏好或代码片段。
检查这段数组代码的形状、广播和视图/副本行为,只给出分析,不要修改文件。

月度数据趋势

累计下载1,657
5111,1271,7422026-03 · 累计下载 5962026-05 · 累计下载 9502026-06 · 累计下载 1,0812026-07 · 累计下载 1,2822026-08 · 累计下载 1,3932026-09 · 累计下载 1,65726-0326-09
星标-
0112026-03 · 星标 -2026-05 · 星标 -2026-06 · 星标 -2026-07 · 星标 -2026-08 · 星标 -2026-09 · 星标 -26-0326-09

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-091,657—-
2026-081,393+8.7%-
2026-071,282+18.6%-
2026-061,081+13.8%-
2026-05950—-
2026-03596—-

SKILL.md 原文

以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。

5.8 KB · ClawHub v1.0.0
---
name: NumPy
slug: numpy
version: 1.0.0
homepage: https://clawic.com/skills/numpy
description: Write fast, memory-efficient numerical code with arrays, broadcasting, vectorization, and linear algebra.
metadata: {"clawdbot":{"emoji":"🔢","requires":{"bins":["python3"]},"os":["linux","darwin","win32"]}}
---

## Setup
展开全部(共 233 行)

On first use, read `setup.md` for integration guidelines. Creates `~/numpy/` to store preferences and snippets.

## When to Use

User needs numerical computing in Python. Agent handles array operations, mathematical computations, linear algebra, and data manipulation with NumPy.

## Architecture

Memory lives in `~/numpy/`. See `memory-template.md` for structure.

```
~/numpy/
├── memory.md      # Preferences + common patterns used
└── snippets/      # User's saved code patterns
```

## Quick Reference

| Topic | File |
|-------|------|
| Setup process | `setup.md` |
| Memory template | `memory-template.md` |

## Core Rules

### 1. Vectorize First
Never use Python loops for array operations. NumPy's vectorized operations are 10-100x faster.

```python
# BAD - Python loop
result = []
for x in arr:
    result.append(x * 2)

# GOOD - Vectorized
result = arr * 2
```

### 2. Understand Broadcasting
Broadcasting allows operations on arrays of different shapes. Know the rules:
- Dimensions align from the right
- Size-1 dimensions stretch to match
- Missing dimensions treated as size-1

```python
# Shape (3,1) + (4,) broadcasts to (3,4)
a = np.array([[1], [2], [3]])  # (3,1)
b = np.array([10, 20, 30, 40])  # (4,)
result = a + b  # (3,4)
```

### 3. Prefer Views Over Copies
Slicing returns views (same memory). Use `.copy()` only when needed.

```python
# View - modifying b changes a
b = a[::2]

# Copy - independent
b = a[::2].copy()
```

### 4. Use Appropriate Dtypes
Choose the smallest dtype that fits your data. Saves memory and speeds up computation.

```python
# For integers 0-255
arr = np.array(data, dtype=np.uint8)

# For floats that don't need double precision
arr = np.array(data, dtype=np.float32)
```

### 5. Axis Awareness
Most functions accept `axis` parameter. Know your axes:
- `axis=0`: operate along rows (down columns)
- `axis=1`: operate along columns (across rows)
- `axis=None` or omit: operate on flattened array

```python
arr = np.array([[1, 2], [3, 4]])
np.sum(arr, axis=0)  # [4, 6] - sum each column
np.sum(arr, axis=1)  # [3, 7] - sum each row
```

### 6. Leverage Built-in Functions
NumPy has optimized functions for common operations. Don't reinvent them.

| Need | Use |
|------|-----|
| Element-wise math | `np.sin`, `np.exp`, `np.log` |
| Statistics | `np.mean`, `np.std`, `np.median` |
| Linear algebra | `np.dot`, `np.linalg.*` |
| Sorting | `np.sort`, `np.argsort` |
| Searching | `np.where`, `np.searchsorted` |

## NumPy Traps

### Shape Mismatches
```python
# TRAP: Confusing (n,) with (n,1) or (1,n)
a = np.array([1, 2, 3])      # shape (3,)
b = np.array([[1, 2, 3]])    # shape (1,3)
c = np.array([[1], [2], [3]])  # shape (3,1)

# FIX: Use reshape or newaxis
a.reshape(-1, 1)  # (3,1)
a[np.newaxis, :]  # (1,3)
```

### Silent Type Coercion
```python
# TRAP: Integer array silently truncates floats
arr = np.array([1, 2, 3])  # int64
arr[0] = 1.9  # becomes 1, not 1.9!

# FIX: Declare dtype upfront
arr = np.array([1, 2, 3], dtype=np.float64)
```

### View vs Copy Confusion
```python
# TRAP: Fancy indexing returns copy, slicing returns view
arr = np.array([1, 2, 3, 4, 5])

# This is a VIEW (changes affect original)
view = arr[1:4]

# This is a COPY (independent)
copy = arr[[1, 2, 3]]
```

### Broadcasting Surprises
```python
# TRAP: Unexpected broadcasting
a = np.array([1, 2, 3])
b = np.array([1, 2])
a + b  # ERROR - shapes don't broadcast

# TRAP: Accidental broadcasting
a = np.zeros((3, 4))
b = np.array([1, 2, 3])
a + b  # ERROR - (3,4) and (3,) don't align
a + b.reshape(-1, 1)  # Works - (3,4) and (3,1)
```

### In-Place Operations
```python
# TRAP: Some operations modify in-place, others don't
np.sort(arr)        # Returns sorted copy
arr.sort()          # Sorts in-place

# Safe pattern: be explicit
arr = np.sort(arr)  # Clear intent
```

## Essential Patterns

### Create Arrays
```python
np.zeros((3, 4))           # All zeros
np.ones((3, 4))            # All ones
np.full((3, 4), 7)         # All sevens
np.eye(3)                  # Identity matrix
np.arange(0, 10, 2)        # [0, 2, 4, 6, 8]
np.linspace(0, 1, 5)       # [0, 0.25, 0.5, 0.75, 1]
np.random.rand(3, 4)       # Uniform [0,1)
np.random.randn(3, 4)      # Normal distribution
```

### Reshape and Stack
```python
arr.reshape(2, 6)          # New shape (must match size)
arr.flatten()              # 1D copy
arr.ravel()                # 1D view
np.concatenate([a, b])     # Join along existing axis
np.stack([a, b])           # Join along new axis
np.vstack([a, b])          # Stack vertically
np.hstack([a, b])          # Stack horizontally
```

### Boolean Indexing
```python
arr = np.array([1, 5, 3, 8, 2])
mask = arr > 3
arr[mask]                  # [5, 8]
arr[arr > 3] = 0           # Replace values > 3 with 0
np.where(arr > 3, 1, 0)    # 1 where >3, else 0
```

### Linear Algebra
```python
np.dot(a, b)               # Matrix multiplication
a @ b                      # Same (Python 3.5+)
np.linalg.inv(a)           # Inverse
np.linalg.det(a)           # Determinant
np.linalg.eig(a)           # Eigenvalues/vectors
np.linalg.solve(a, b)      # Solve Ax = b
```

## Security & Privacy

**Data that stays local:**
- All computations run locally
- Code patterns saved in ~/numpy/

**This skill does NOT:**
- Send data externally
- Access files outside ~/numpy/
- Require network connectivity

## Related Skills
Install with `clawhub install <slug>` if user confirms:
- `data` — data processing workflows
- `math` — mathematical computations
- `statistics` — statistical analysis

## Feedback

- If useful: `clawhub star numpy`
- Stay updated: `clawhub sync`

「开发编程」分类下的热门技能

Iván 的其他技能

数据月份:2026-09 · 下载/星标/安装数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。