Python for Data Science Cheat Sheet: NumPy Basics
Tags
Summary
This book is the NumPy Basics page from the DataCamp series Python for Data Science Cheat Sheet. In a single page it lists the most common ways to write NumPy, the scientific computing library, so you do not need to start from the beginning; when a specific question comes up, you can quickly look up the corresponding syntax. Contents include: importing the library by the convention `import numpy as np`; creating arrays, such as array literals, `zeros`, `ones`, `arange`, `linspace`, `full`, `eye`, `random.random`, `empty`, and more; saving and loading data (`save`, `savez`, `load`, plus `loadtxt`, `genfromtxt`, `savetxt` for text files); common data types and type conversion; inspecting array attributes (`shape`, `ndim`, `size`, `dtype`, `astype`); arithmetic operations and universal functions (addition, subtraction, multiplication, division, exponents, square roots, trigonometric functions, logarithms, dot products); comparison and aggregate statistics (`sum`, `min`, `max`, `cumsum`, `mean`, `median`, `std`, etc.); array reshaping, joining, and splitting (`reshape`, `ravel`, `transpose`, `concatenate`, `vstack`, `hstack`, `split`, etc.); and diagrams of one- to three-dimensional arrays that help explain array shapes and the meaning of axes. Each code snippet comes with a short explanation; this is a reference sheet, not a tutorial.
Editor's review
NumPy 的 API 不算多,但细节零碎:建数组的方法有好几种,axis 参数的方向容易记混,各种变形和拼接函数的差别也很难记住。这份速查表的优点在于把最常用的调用集中到一页上,并且每个都配了简短的英文注释和代码示例,可以打印出来贴在工位上,也可以放在第二块屏幕上,写代码时直接对照着查。读者最好已经学过 Python 基础语法。如果完全没接触过数组编程,只看这一页可能不够,建议配合教材或课程一起用;有基础的人用它来复习和提速,效果会更好。
Who it's for
A good fit for
- 刚学完 Python 语法、准备入门 NumPy 的读者,可以对照速查表上手
- 经常写数据分析或科学计算代码、需要随手查函数用法的人
- 正在上网课或自学(如 DataCamp 课程)的读者,可把它当随堂参考
- 需要一页纸备忘、便于打印张贴的工程技术人员
Not a good fit for
- 没有 Python 基础、需要系统讲解和习题的读者
- 想深入理解广播机制、内存布局与性能原理的读者,这份材料只列用法不展开
Reading tips
- 先通读一遍,对建数组、索引、变形、聚合四类操作各挑一行跑一遍,确认环境能正常运行。
- 把速查表里的片段手敲进 Jupyter 并修改参数,观察 shape 和 dtype 的变化,记忆效果会比只看强得多。
- 把不熟悉的函数记进自己的笔记,再查 NumPy 官方文档的对应章节补充参数细节和示例。
- 和 Pandas 速查表对照着用,理解数组与数据框在索引、聚合上的差异。
FAQ
这份速查表和整套「Python数据科学速查表」是什么关系?
「Python数据科学速查表」是 DataCamp 发布的一系列单页速查材料,按主题分册,分别讲 NumPy、Pandas、Matplotlib、Seaborn 等。本书是其中讲 NumPy 基础的那一份,不是独立成书的教程。
需要先学完 Python 再学 NumPy 吗?
建议先掌握变量、列表、函数、循环等基础语法。速查表只列函数与写法,不解释语法,没有基础的话看起来会比较吃力。
这些内容是针对哪个 NumPy 版本?
原始速查表发布较早,部分写法(如 `np.string_`、`np.unicode_`)在新版 NumPy 中已弃用或移除。实际使用时请以当前官方文档为准,遇到报错先查版本变更。
打印出来有用吗?
有用。速查表本来就是一页纸的定位,打印贴在工位或夹在笔记本里,写代码时比对函数名和参数顺序都很方便,可以省去反复搜索的时间。
看完速查表下一步学什么?
可以继续看同一系列讲 Pandas 和 Matplotlib 的速查表,或者读 NumPy 官方用户指南中关于广播、索引和数组视图的章节,把用法背后的机制补上。
Comments
Find this book
This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.