Hướng dẫn người dùng NumPy
Một cái nhìn tổng quan toàn diện và hướng dẫn kỹ thuật giới thiệu về NumPy, bao gồm cài đặt, thao tác mảng, truy cập chỉ mục, phát sóng và tích hợp với C/C++.
Tổng quan khóa học
📚 Tổng quan Nội dung
Một bản tổng quan giới thiệu toàn diện và hướng dẫn kỹ thuật về NumPy, bao gồm cài đặt, thao tác mảng, truy cập, phát triển (broadcasting), và tích hợp với C/C++.
Thành thạo nền tảng tính toán khoa học trong Python với hướng dẫn chính thức của NumPy.
Tác giả: Cộng đồng NumPy
Ghi nhận: Được viết bởi cộng đồng NumPy
🎯 Mục tiêu Học tập
- Định nghĩa NumPy và xác định vai trò của nó trong hệ sinh thái Python khoa học.
- Giải thích tại sao NumPy nhanh hơn đáng kể so với các vòng lặp Python thông thường bằng khái niệm vector hóa.
- Thực hiện lệnh cài đặt cho nhiều môi trường khác nhau bao gồm Pip, Conda và Raspberry Pi.
- Nhận diện và diễn giải các thuộc tính cốt lõi
ndarraynhưndim,shapevàdtype. - Thực hiện tạo và thao tác mảng bằng các hàm như
linspace,reshape,vstackvàhstack. - Áp dụng các phép toán từng phần tử, hàm phổ biến (ufuncs) và bộ giải phương trình đại số tuyến tính cho dữ liệu số.
- Quản lý độ chính xác dữ liệu và giảm thiểu lỗi tràn số bằng các kiểu số nguyên và công cụ thông tin (
iinfo,finfo) của NumPy. - Thực hiện nhập dữ liệu linh hoạt từ đĩa sử dụng
genfromtxtvới dấu phân cách tùy chỉnh, tiêu đề và lựa chọn cột. - Áp dụng Quy tắc Phát triển Chung để dự đoán và kiểm soát tương tác giữa các mảng có hình dạng khác nhau.
- Quản lý tham chiếu bộ nhớ và tránh "bẫy" trong các lớp con
ndarraytùy chỉnh bằng thuộc tính.base.
Bài học 共 5 课时 · 预计 15.0h
Bài học
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.