← スキル一覧に戻る

numpy-string-ops
by cuba6112
⭐ 0🍴 0📅 2025年12月26日
SKILL.md
name: numpy-string-ops description: Vectorized string manipulation using the char module and modern string alternatives, including cleaning and search operations. Triggers: string operations, numpy.char, text cleaning, substring search.
Overview
NumPy's char submodule provides vectorized versions of standard Python string operations. It allows for efficient processing of arrays containing str_ or bytes_ types, though it is being transitioned to a newer strings module in recent versions.
When to Use
- Cleaning large text datasets (e.g., stripping whitespace, normalization).
- Performing batch substring searches across thousands of records.
- Concatenating columns of text data using broadcasting.
- Converting character casing for entire datasets simultaneously.
Decision Tree
- Starting new development?
- Use
numpy.stringsif available;numpy.charis legacy.
- Use
- Comparing strings with potential trailing spaces?
numpy.charcomparison operators automatically strip whitespace.
- Concatenating a constant prefix to an array of names?
- Use
np.char.add(prefix, name_array).
- Use
Workflows
-
Batch String Concatenation
- Create two arrays of strings, A and B.
- Use
np.char.add(A, B)to join them element-wise. - Broadcasting applies if one array is a single string and the other is multidimensional.
-
Cleaning Text Datasets
- Identify an array of messy text.
- Apply
np.char.strip(arr)to remove whitespace. - Use
np.char.lower(arr)to normalize casing across the entire dataset.
-
Finding Substrings in Arrays
- Use
np.char.find(text_array, 'target_word'). - Identify elements with non-negative indices (where the word was found).
- Filter the original array using boolean indexing based on the search result.
- Use
Non-Obvious Insights
- Legacy Status: The
charmodule is considered legacy; future-proof code should look towards thenumpy.stringsalternative. - Implicit Stripping: Unlike standard Python
==,charmodule comparison operators strip trailing whitespace before evaluating equality. - Vectorization Reality: While these operations are vectorized, string manipulation is inherently less performant than numeric math because strings have variable lengths and require more complex memory management.
Evidence
- "Unlike the standard numpy comparison operators, the ones in the char module strip trailing whitespace characters before performing the comparison." Source
- "The numpy.char module provides a set of vectorized string operations for arrays of type numpy.str_ or numpy.bytes_." Source
Scripts
scripts/numpy-string-ops_tool.py: Routines for batch text cleaning and search.scripts/numpy-string-ops_tool.js: Simulated string concatenation logic.
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
レビュー
💬
レビュー機能は近日公開予定です