Cette page est affichée en anglais. Une traduction française est en cours.
SkillsApr 12, 2026·3 min de lecture

NumPy — The Fundamental Package for Scientific Computing

NumPy is the foundation of the Python scientific computing ecosystem. It provides high-performance multidimensional arrays, mathematical functions, linear algebra, random number generation, and Fourier transforms — powering pandas, scikit-learn, TensorFlow, and more.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
step-1.md
Commande d'installation directe
npx -y tokrepo@latest install 1066ae73-366d-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

TL;DR
NumPy provides the array data structure and mathematical operations that power the entire Python data science ecosystem.
§01

What it is

NumPy (Numerical Python) is the bedrock of the Python data science and machine learning ecosystem. It provides high-performance multidimensional arrays (ndarray), mathematical functions, linear algebra, random number generation, and Fourier transforms. Nearly every scientific Python library -- pandas, scikit-learn, TensorFlow, PyTorch -- builds on NumPy's array interface.

It is designed for scientists, data analysts, and ML engineers who need fast numerical operations in Python without writing C or Fortran code.

§02

How it saves time or tokens

NumPy vectorized operations run 10-100x faster than equivalent Python loops because they execute in compiled C code. Broadcasting eliminates the need for explicit loops over array dimensions. The universal function (ufunc) system lets you apply operations across entire arrays in a single call.

§03

How to use

  1. Install: pip install numpy
  2. Import: import numpy as np
  3. Create arrays and perform operations using vectorized functions
§04

Example

import numpy as np

# Create arrays
a = np.array([1, 2, 3, 4, 5])
b = np.random.randn(3, 4)  # 3x4 random matrix

# Basic statistics
print(f'Mean: {b.mean():.3f}, Std: {b.std():.3f}')
print(f'Matrix shape: {b.shape}')

# Linear algebra
A = np.array([[1, 2], [3, 4]])
inverse = np.linalg.inv(A)
eigenvalues = np.linalg.eigvals(A)

# Broadcasting: add a vector to each row of a matrix
matrix = np.random.randn(1000, 3)
offset = np.array([1.0, -0.5, 2.0])
result = matrix + offset  # No loop needed

# Vectorized operations: 100x faster than Python loops
x = np.linspace(0, 2 * np.pi, 10000)
y = np.sin(x) * np.exp(-x / 5)
§05

Related on TokRepo

§06

Common pitfalls

  • NumPy arrays have a fixed dtype; mixing integers and floats silently converts the entire array, which can cause precision issues
  • Views vs copies: slicing creates a view (shared memory), not a copy; modifying a slice modifies the original array
  • Large array operations can exhaust memory; use memory-mapped files (np.memmap) for datasets larger than RAM

Questions fréquentes

How is NumPy different from Python lists?+

NumPy arrays are homogeneous (single data type), stored contiguously in memory, and support vectorized operations in compiled C code. Python lists are heterogeneous, store object pointers, and require explicit loops. NumPy is 10-100x faster for numerical operations.

Does NumPy use GPU acceleration?+

NumPy itself runs on CPU only. For GPU acceleration, use CuPy (a NumPy-compatible GPU library), JAX, or PyTorch. These libraries provide NumPy-like APIs that run on NVIDIA GPUs.

What is broadcasting in NumPy?+

Broadcasting is NumPy's mechanism for performing operations on arrays with different shapes. Instead of writing loops to match dimensions, NumPy automatically expands the smaller array to match the larger one during arithmetic operations.

How do I save and load NumPy arrays?+

Use np.save and np.load for binary format (.npy), np.savez for compressed archives, or np.savetxt and np.loadtxt for text files. The binary format is faster and preserves data types exactly.

Is NumPy still relevant with pandas and PyTorch available?+

Yes. pandas and PyTorch both build on NumPy's array interface. Understanding NumPy is essential for working effectively with any scientific Python library. Many operations are more efficient when done at the NumPy level.

Sources citées (3)
  • NumPy Official Site— NumPy is the fundamental package for scientific computing in Python
  • NumPy GitHub— NumPy's ndarray is the foundation for pandas, scikit-learn, TensorFlow
  • NumPy Documentation— Vectorized operations and broadcasting documentation

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires