We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
numpy 函数
数据类型
数组和标量之间的运算
数组很重要,因为它使你不用编写循环即可对数据执行批量运算。这通常就叫做矢量化(vectorization)。大小相等的数组之间的任何算术运算都会将运算应用到元素级。不同大小的数组之间的运算叫做广播(broadcasting)。
基本的索引和切片
arr = np.arange(10) arr # array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) arr[5:8] # array([5, 6, 7]) arr[5:8] = 12 # array([0, 1, 2, 3, 4, 12, 12, 12, 8, 9])
想要得到一份副本而非视图, 需要显示的复制, 例如: arr[5:8].copy()
多维数组访问
切片是沿着一个轴向选取元素的。你可以一次传入多个切片,就像传入多个索引那样:
In[78]:arr2d[:2,1:] Out[78]:array([[2,3],[5,6]])
像这样进行切片时,只能得到相同维数的数组视图。通过将整数索引和切片混合,可以得到低维度的切片:
In[79]:arr2d[1,:2] In[80]:arr2d[2,:1] Out[79]:array([4,5]) Out[80]:array([7])
布尔类型数组索引
data[names == 'Bob',3] data[names != 'Bob',3] data[-(names == 'Bob'),3] data[age < 20 ,3] ...
Python关键字and和or在布尔型数组中无效。
花式索引
花式索引总是将数据复制到新数组中
数组转置和轴对换
np.dot(arr.T , arr)
通用函数: 快速的元素级数组函数
将条件逻辑表述为数组运算
np.where
数学和统计方法
Sum、mean 以及标准差std 等聚合计算(约简计算), 既可以当作数组的实例方法也可以当作顶级NumPy函数使用
arr = np.random.randn(5,4) # 模拟正态分布的数据 arr.mean() # 0.062814911084854597 np.mean(arr) # 0.062814911084854597
用于布尔型数组的方法
arr = randn(100) (arr > 0).sum() bools = np.array([False, False, True, False]) bools.any() # True bools.all() # False
排序 Sort
唯一化
np.unique 找出数组中的唯一值,并且返回已排序的结果
用于数组的文件输入输出
np.save 和 np.load np.savez和 np.load np.savetxt和 np.loadtext
arr = np.arange(10) np.save('some_array', arr) # 后缀 .npy np.load('some_array.npy') np.loadtxt('some_ex.txt', delimiter=',')# 以逗号隔开的文本文件 np.savetxt('some_ex.txt', arr)
线性代数
随机数生成
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Data Analysis with Python——02
Numpy
numpy 函数
![Screen Shot 2019-03-11 at 3.25.13 PM.png](https://camo.githubusercontent.com/e96a842c3297d04d0ecf6ed2cef7386b0504af7abb05d567c0dc0d16bd1ef70b/68747470733a2f2f692e6c6f6c692e6e65742f323031392f30382f32332f546f555076395334356b63756c497a2e706e67)
数据类型
数组和标量之间的运算
数组很重要,因为它使你不用编写循环即可对数据执行批量运算。这通常就叫做矢量化(vectorization)。大小相等的数组之间的任何算术运算都会将运算应用到元素级。不同大小的数组之间的运算叫做广播(broadcasting)。
基本的索引和切片
多维数组访问
切片是沿着一个轴向选取元素的。你可以一次传入多个切片,就像传入多个索引那样:
像这样进行切片时,只能得到相同维数的数组视图。通过将整数索引和切片混合,可以得到低维度的切片:
布尔类型数组索引
花式索引
数组转置和轴对换
通用函数: 快速的元素级数组函数
将条件逻辑表述为数组运算
np.where
数学和统计方法
Sum、mean 以及标准差std 等聚合计算(约简计算), 既可以当作数组的实例方法也可以当作顶级NumPy函数使用
用于布尔型数组的方法
经常用来对布尔型数组中的True 值计数
是否存在一个或多个True
都是True
排序
Sort
唯一化
np.unique
找出数组中的唯一值,并且返回已排序的结果
用于数组的文件输入输出
np.save 和 np.load
np.savez和 np.load
np.savetxt和 np.loadtext
线性代数
![Screen Shot 2019-03-11 at 4.21.19 PM.png](https://camo.githubusercontent.com/a50f12204260e4e6427ef79c221c5b54d876c7c69bc55115c7f78e9b2358ffd4/68747470733a2f2f692e6c6f6c692e6e65742f323031392f30382f32332f7332637a53705965355a614d6c38452e706e67)
随机数生成
![Screen Shot 2019-03-11 at 4.22.35 PM.png](https://camo.githubusercontent.com/b132e948172585aeec53d696518a9984ec072fd9ddf2dbe5708ad28df1793675/68747470733a2f2f692e6c6f6c692e6e65742f323031392f30382f32332f416d6956734878494c3955503174422e706e67)
The text was updated successfully, but these errors were encountered: