一、通用函数:快速的元素级数组函数
通用函数(即ufunc)是一种对ndarray中的数据执行元素级运算的函数。你可以将其看作是简单的函数(接受一个或多个标量值,并产生一个或多个标量值)的矢量化包装器。
1、一元ufunc


eg:



2、二元ufunc

eg:

二、利用数组进行数据处理
numpy数组使你可以将许多种数据处理任务表述为简洁的数组表达(否则需要编写循环)。
用数组表达式代替循环的做法,通常被称为矢量化。
eg: 假设我们想要在一组值上计算函数sqrt(x^2 + y^2)。np.meshgrid函数接受两个一维数组,并产生两个二维矩阵(对应两个数组中所有的(x,y)对)



1、将条件逻辑表述为数组运算
numpy.where函数是三元表达式 x if condition else y 的矢量化版本。假设我们有一个布尔数组和两个值数组:


2、数学和统计方法
可以通过数组上的一组数学函数对整个数组或某个轴向的数据进行统计。sum,mean以及标准差std等聚合计算既可以当做数组实例方法调用,也可以当做顶级NumPy函数使用。







3、用于布尔数组的方法

4、排序
sort()函数

5、唯一化及其他的集合逻辑
unique()
与其等价的python纯代码:
sorted(set(name))




eg:

网友评论