← スキル一覧に戻る

numpy-io
by cuba6112
⭐ 0🍴 0📅 2025年12月26日
SKILL.md
name: numpy-io description: File I/O operations including binary formats (npy/npz), text processing (csv), and memory-mapping for huge datasets. Triggers: io, load, save, npz, genfromtxt, memmap, loadtxt.
Overview
NumPy I/O handles the transition of data between system memory and persistent storage. It supports highly efficient binary formats (.npy, .npz), flexible text parsers for messy data, and memory-mapping for datasets that exceed available RAM.
When to Use
- Storing model weights or large datasets in a compressed binary format.
- Reading messy CSV files with missing data or mixed types.
- Processing multi-gigabyte datasets without loading the entire file into memory.
- Bundling multiple related arrays into a single archive file.
Decision Tree
- Storing data for future NumPy use?
- Use
.npyfor single arrays,.npzfor multiple arrays.
- Use
- Is the file larger than your RAM?
- Use
np.memmapto access disk segments lazily.
- Use
- Reading a clean CSV?
- Use
np.loadtxt(fast).
- Use
- Reading a messy CSV with missing values?
- Use
np.genfromtxt(feature-rich but slower).
- Use
Workflows
-
Handling Large Disk-Bound Arrays
- Create a memory-mapped file with
np.memmap(filename, dtype='float32', mode='w+', shape=shape). - Process or fill the array as if it were in memory.
- Call
.flush()to ensure all data is written to the physical disk.
- Create a memory-mapped file with
-
Importing Messy CSV Data
- Define a dictionary of converters for specific columns.
- Use
np.genfromtxt(csv_file, delimiter=',', skip_header=1, converters=converters). - Access the data which now has NaNs or default values where data was missing.
-
Bundling Multiple Arrays for Storage
- Identify several related ndarrays.
- Save them into a single archive with
np.savez_compressed('data.npz', arr1=arr1, arr2=arr2). - Load them later using
data = np.load('data.npz')and access viadata['arr1'].
Non-Obvious Insights
- Manual Flush Requirement: Changes to a
memmaparray are not guaranteed to persist on disk until.flush()is called. - NPZ Lazy Loading:
.npzfiles are ZIP archives;np.loadon an.npzdoes not load the data until you access a specific key. - Parser Capability:
genfromtxthandles column selection, comment characters, and missing value substitution automatically, making it the primary tool for "real-world" text data.
Evidence
- "Memory-mapped files are used for accessing small segments of large files on disk, without reading the entire file into memory." Source
- "savez_compressed... Save several arrays into a single file in compressed .npz format." Source
Scripts
scripts/numpy-io_tool.py: Functions for memmap creation and compressed npz saving.scripts/numpy-io_tool.js: Basic CSV line parser simulation.
Dependencies
numpy(Python)
References
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です