Numpy Performance logo

Numpy Performance

Community
0xBakeer
numpy-performance

Making numeric Python fast with NumPy - vectorizing loops, broadcasting, dtypes and memory, avoiding copies, and measuring with timeit before and after.

Overview

Publisher0xBakeer
RepositoryTandemLLM
Skill namenumpy-performance
Stars
75
Forks
14
Bundled files
Instructions only
LicenseAGPL-3.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by 0xBakeer on GitHub. Read the source before you install it.

Installation

Install the Numpy Performance AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/numpy-performance
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/0xBakeer/TandemLLM.git /tmp/TandemLLM
mkdir -p .claude/skills
cp -r /tmp/TandemLLM/packages/library/numpy-performance .claude/skills/numpy-performance
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Numpy Performance in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Numpy Performance on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Numpy Performance is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

NumPy performance

Rules:

  • Measure first: timeit the slow function on a realistic size (the real N, not 10). Write the number down before changing anything.
  • Replace Python loops over arrays with array expressions: slicing, broadcasting, np.where, np.cumsum, np.einsum, boolean masks.
  • Choose the dtype: float32 halves memory and often doubles speed when 7 digits are enough; int64 for indices and counts. Say which and why.
  • Allocate once outside loops; use out= and in-place operators (a += b) on hot paths.

What goes wrong:

  • np.append in a loop: quadratic. Collect in a list, convert once, or preallocate.
  • Broadcasting an (N,1) against (N,) creates (N,N) by accident; memory explodes. Print shapes.
  • float64 to float32 conversion inside the loop every iteration.

Check: time the old and the new version on the same input, show both numbers and the speedup, and np.allclose(old, new) with the tolerance stated.

Done when:

  • Before and after timings on the real size in the result (ms, and the ratio).
  • np.allclose(old, new, rtol=1e-6) is True (or the differences explained).
  • Peak memory or the array shapes and dtypes printed for the hot arrays.

Reference

Timing:

python
import timeit, numpy as np
x = np.random.default_rng(0).random(1_000_000)
t_old = timeit.timeit(lambda: f_old(x), number=5) / 5
t_new = timeit.timeit(lambda: f_new(x), number=5) / 5
print(f"old {t_old*1e3:.1f} ms  new {t_new*1e3:.1f} ms  x{t_old/t_new:.1f}  close={np.allclose(f_old(x), f_new(x))}")

Loop to vector:

python
# before
out = np.empty(len(x))
for i in range(1, len(x)): out[i] = out[i-1] * 0.9 + x[i]
# after (moving sum, distances, conditionals)
m = np.convolve(x, np.ones(5) / 5, mode="valid")
d = np.sqrt(((p[:, None, :] - q[None, :, :]) ** 2).sum(-1))   # (N, M) distances; watch memory N*M*8 bytes
y = np.where(x > 0.5, x, 0.0)

Preallocate and in-place: acc = np.zeros(n, dtype=np.float32); np.add(acc, x, out=acc). Memory: a.nbytes / 1e6 MB; np.shares_memory(a, b) to check views; np.ascontiguousarray(a) before passing to C code. numba for an unavoidable recurrence:

python
from numba import njit
@njit(cache=True)
def ewma(x, a):
    out = np.empty_like(x); out[0] = x[0]
    for i in range(1, len(x)): out[i] = a * x[i] + (1 - a) * out[i-1]
    return out

Peak memory: /usr/bin/time -l python script.py (macOS) or -v (Linux), read "maximum resident set size".

More rules:

  • Know what copies: fancy indexing and np.concatenate copy; slices and reshape of contiguous arrays do not. Check a.flags["C_CONTIGUOUS"] before a hot loop.
  • Beyond NumPy, in this order: numba for an unavoidable loop, then scipy routines, then a GPU library, each justified by a measured number.

More pitfalls:

  • A "vectorized" version that gives different results from the loop; compare with np.allclose before trusting the speedup.

Frequently asked questions

What does the Numpy Performance AI skill do?

Making numeric Python fast with NumPy - vectorizing loops, broadcasting, dtypes and memory, avoiding copies, and measuring with timeit before and after.

Why use Numpy Performance on TypingMind?

Because you install it once and use it with any model. Numpy Performance is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Numpy Performance in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/numpy-performance. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Numpy Performance?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Numpy Performance?

As many as you like. As long as a model supports skills, you can use Numpy Performance with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Numpy Performance AI skill free?

Yes. It is published on GitHub by 0xBakeer under the AGPL-3.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇