Agent skill

numpy-numerical-analysis-1-use-vectorization

Sub-skill of numpy-numerical-analysis: 1. Use Vectorization (+3).

Stars 4
Forks 4

Install this agent skill to your Project

npx add-skill https://github.com/vamseeachanta/workspace-hub/tree/main/.claude/skills/_archive/data/scientific/numpy-numerical-analysis/1-use-vectorization

SKILL.md

1. Use Vectorization (+3)

1. Use Vectorization

python
# ❌ Bad: Loop
result = np.zeros(len(x))
for i in range(len(x)):
    result[i] = x[i]**2 + y[i]**2

# ✅ Good: Vectorized
result = x**2 + y**2

2. Avoid Unnecessary Copies

python
# ❌ Bad: Creates copies
a = np.array([1, 2, 3])
b = a
b[0] = 10  # Modifies original

# ✅ Good: Explicit copy when needed
a = np.array([1, 2, 3])
b = a.copy()
b[0] = 10  # Original unchanged

3. Use In-Place Operations

python
# ❌ Bad: Creates new array
a = a + 1

# ✅ Good: In-place
a += 1

4. Choose Appropriate Data Types

python
# Use float32 for large arrays when precision allows
large_array = np.zeros((10000, 10000), dtype=np.float32)  # 400 MB instead of 800 MB

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

Didn't find tool you were looking for?

Be as detailed as possible for better results