返回課程
AI018 專業人士

NumPy 使用者指南

一份全面的入門概覽與技術指南,介紹 NumPy 的安裝、陣列操作、索引、廣播功能,以及與 C/C++ 的整合。

4.9
15.0h
891 學習者
5 lessons
0 讚好
人工智能
開始學習

課程總覽

📚 內容摘要

一份全面的入門概述與技術指南,涵蓋 NumPy 的安裝、陣列操作、索引、廣播機制,以及與 C/C++ 的整合。

透過官方 NumPy 指南,掌握科學計算在 Python 中的基礎。

作者: NumPy 社群

致謝: 由 NumPy 社群撰寫

🎯 學習目標

  1. 定義 NumPy 並識別其在科學計算型 Python 生態系統中的角色。
  2. 解釋為何 NumPy 比標準 Python 迴圈快得多,並運用「向量化」的概念說明。
  3. 執行各種環境(包括 Pip、Conda 及 Raspberry Pi)的安裝指令。
  4. 識別並解讀核心 ndarray 屬性,如 ndimshapedtype
  5. 使用 linspacereshapevstackhstack 等函數執行陣列建立與操作。
  6. 對數值資料集應用元素級運算、通用函數(ufuncs)及線性代數求解器。
  7. 利用 NumPy 的標量類型與資訊工具(iinfofinfo)管理資料精確度,並避免溢位錯誤。
  8. 使用 genfromtxt 以自訂分隔符、標頭與欄位選擇,靈活地從磁碟讀取資料。
  9. 應用通用廣播規則,預測並控制不同形狀陣列之間的互動。
  10. 管理記憶體參考,並透過 .base 屬性避免自訂 ndarray 子類別中的「陷阱」。

課程

Lesson

This lesson introduces NumPy as the foundational bridge between high-level Python applications and low-level hardware, focusing on the ndarray as a universal interface for scientific computing. Students will learn how the ndarray’s contiguous memory layout and homogeneous data structure enable high-performance, vectorized operations across the data science ecosystem.

This lesson introduces the NumPy ndarray as a memory-efficient, homogeneous alternative to Python lists, focusing on proper initialization and the performance benefits of contiguous memory. Students will learn to interpret core array attributes—such as shape, size, and data type—to understand how metadata defines the spatial geometry and memory footprint of numerical data.

This lesson covers precision management in NumPy, focusing on how fixed-size data types handle integer overflow and floating-point saturation. It also introduces robust data ingestion techniques using np.genfromtxt to handle irregular file formats and sanitize messy datasets.

This lesson explores the complexities of subclassing `numpy.ndarray`, focusing on the "Initialization Triad" and the critical role of the `__array_finalize__` hook in maintaining metadata. Students will learn to navigate the risks of behavioral fragility and identify when to choose subclassing for interoperability versus using composition for safer architectural design.

AI018: Extending NumPy with the C-API (Lesson 5) explores how to overcome performance bottlenecks like the interpreter tax and memory bloat by implementing high-performance C extensions. Students will learn to manage memory safely, utilize kernel fusion, and perform cache-aligned pointer arithmetic to optimize complex computational tasks.