Token导航 LogoToken导航TokenDH.com
前端设计需要联网github未标认证来源可访问许可证需确认审计提醒

numpy-low-levelnumpy 低级

Agent Skill

numpy-low-level 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

445

周安装

18

GitHub Stars

9

下载量

140
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:numpy-low-level(numpy 低级)
来源仓库:https://github.com/tondevrel/scientific-agent-skills
仓库路径:skills/numpy-low-level
安装命令:
npx skills add https://github.com/tondevrel/scientific-agent-skills --skill numpy-low-level
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/tondevrel/scientific-agent-skills --skill numpy-low-level

简介

numpy-low-level 用于处理 GitHub 仓库、Issue 和 Pull Request 协作信息。

  • 适用于围绕仓库状态、代码变更或协作事项进行整理。
  • 通过 npx skills add 命令安装,需结合原始 README 确认具体用法。
  • 安装前建议确认权限范围、维护状态及是否触发联网或文件读写操作。
  • 可结合来源仓库进一步核验功能细节和使用限制。

SKILL.md

NumPy - Low-Level Optimization & Memory

At high volumes, standard NumPy operations can still be slow due to unnecessary memory allocations. This guide covers how to manipulate the internal representation of arrays to achieve C-level performance without leaving Python.

When to Use

  • Implementing sliding window algorithms (convolutions) without extra memory.
  • Interfacing Python with C, C++, or Fortran code via pointers.
  • Working with complex, heterogeneous data structures (Structured Arrays).
  • Optimizing memory-constrained systems via Memory Mapping (memmap).
  • Debugging performance issues related to "Memory Layout" (C-style vs Fortran-style).

Core Principles

1. The Metadata vs. Data Split

A NumPy array is a small Header (shape, dtype, strides) pointing to a large Data Buffer. Many operations (like .T, reshape, slice) only change the Header. This is "Zero-Copy".

2. Strides (The Step Logic)

Strides define how many bytes to skip in memory to get to the next element in each dimension. Manipulating strides allows you to "cheat" and create virtual views of data.

3. Contiguity

  • C-Contiguous: Last index varies fastest (Row-major).
  • F-Contiguous: First index varies fastest (Column-major).
  • Vectorization is significantly faster on contiguous memory.

Quick Reference: Memory Inspection

import numpy as np

arr = np.zeros((100, 100))

print(arr.flags)         # Check contiguity and ownership
print(arr.strides)       # bytes to step in each axis
print(arr.__array_interface__['data']) # Memory pointer address

Critical Rules

✅ DO

  • Prefer Views over Copies - Use slicing and reshaping whenever possible.
  • Check base - Use arr.base is None to verify if an array owns its memory or is just a view.
  • Use Structured Arrays - For "Table of Records" data where you need NumPy speed but different types per column.
  • Align Memory - Ensure arrays are aligned to 64-bit boundaries for SIMD optimization.
  • Use out= parameters - Most NumPy functions accept an out argument to prevent creating a new temporary array.

❌ DON'T

  • Don't use np.append or np.concatenate in loops - These are O(N²) because they copy the entire buffer every time.
  • Don't ignore the "Copy Warning" - Fancy indexing (arr[[1, 3, 5]]) always creates a copy, unlike basic slicing.
  • Don't use as_strided blindly - It is the most dangerous function in NumPy. It can lead to memory corruption or crashes if bounds are miscalculated.

Low-Level Patterns

1. Sliding Windows (Zero-Copy Convolution)

from numpy.lib.stride_tricks import as_strided

def sliding_window_1d(arr, window_size):
    """Creates a virtual 2D view of a 1D array for rolling stats."""
    itemsize = arr.itemsize
    shape = (arr.size - window_size + 1, window_size)
    strides = (itemsize, itemsize)
    return as_strided(arr, shape=shape, strides=strides)

# Result is a 2D array where each row is a window,
# but it uses NO additional memory.

2. Structured Arrays (Interoperable C-structs)

# Define a record type: Name (32 chars), Age (int), Salary (float)
dtype = np.dtype([('name', 'S32'), ('age', 'i4'), ('salary', 'f8')])

data = np.array([('Alice', 25, 50000), ('Bob', 30, 60000)], dtype=dtype)

# Access by field name (Fast, vectorized)
print(data['salary'].mean())

Interfacing with C-API

Using ctypes pointers

import ctypes

# Get raw pointer to data
ptr = arr.ctypes.data_as(ctypes.POINTER(ctypes.c_double))

# This pointer can be passed to a C/C++ library
# for direct manipulation of the NumPy buffer.

Performance Optimization

Vectorized Math with out=

# ❌ SLOW: Creates 3 temporary arrays
# res = (a * b) + c

# ✅ FAST: Reuse memory
np.multiply(a, b, out=a) # a now holds a*b
np.add(a, c, out=a)      # a now holds (a*b)+c

Memory Mapping for Huge Data

# Create an array that stays on disk, reading only what's needed
huge_data = np.memmap('data.bin', dtype='float32', mode='w+', shape=(10000, 10000))

Common Pitfalls

Broadcast Copying

If you broadcast a small array across a large one, NumPy doesn't copy the small one; it just sets the stride to 0.

# strides of a (10, 1) array broadcasted to (10, 100):
# (8, 0) -> It keeps reading the same memory for the second axis!

The Byte-Order (Endianness)

Scientific data from old instruments might be Big-Endian.

# Convert in-place without copying
raw_data = np.frombuffer(buffer, dtype='>f4').view('<f4')

NumPy Low-Level is about removing abstractions. By mastering strides and the array interface, you turn Python into a thin wrapper over raw memory, enabling "impossible" data manipulations at hardware speeds.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.23%
按下载量换算51

Claude

27.99%
按下载量换算39

Cursor

21.42%
按下载量换算30

Gemini CLI

9.57%
按下载量换算13

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills