更多关于:NumPy…
数学运算函数
add(x1,x2 [,out]) | 按元素添加参数,等效于 x1 + x2 |
subtract(x1,x2 [,out]) | 按元素方式减去参数,等效于x1 – x2 |
multiply(x1,x2 [,out]) | 逐元素乘法参数,等效于x1 * x2 |
divide(x1,x2 [,out]) | 逐元素除以参数,等效于x1 / x2 |
exp(x [,out]) | 计算输入数组中所有元素的指数。 |
exp2(x [,out]) | 对于输入数组中的所有p,计算2 ** p。 |
log(x [,out]) | 自然对数,逐元素。 |
log2(x [,out]) | x的基础2对数。 |
log10(x [,out]) | 以元素为单位返回输入数组的基数10的对数。 |
expm1(x [,out]) | 对数组中的所有元素计算exp(x) - 1 |
log1p(x [,out]) | 返回一个加自然对数的输入数组,元素。 |
sqrt(x [,out]) | 按元素方式返回数组的正平方根。 |
square(x [,out]) | 返回输入的元素平方。 |
sin(x [,out]) | 三角正弦。 |
cos(x [,out]) | 元素余弦。 |
tan(x [,out]) | 逐元素计算切线。 |
››› x = np.random.randint(4, size=6).reshape(2,3) ››› x array([[2, 0, 3], [2, 3, 3]]) ››› y = np.random.randint(4, size=6).reshape(2,3) ››› y array([[1, 3, 1], [1, 1, 0]]) ››› ››› x + y array([[3, 3, 4], [3, 4, 3]]) ››› np.add(x, y) array([[3, 3, 4], [3, 4, 3]]) ››› np.square(x) array([[4, 0, 9], [4, 9, 9]]) ››› np.log1p(x) array([[ 1.09861229, 0. , 1.38629436], [ 1.09861229, 1.38629436, 1.38629436]])
规约函数
下面所有的函数都支持axis来指定不同的轴,用法都是类似的。
ndarray.sum([axis,dtype,out,keepdims]) | 返回给定轴上的数组元素的总和。 |
ndarray.cumsum([axis,dtype,out]) | 返回沿给定轴的元素的累积和。 |
ndarray.mean([axis,dtype,out,keepdims]) | 返回沿给定轴的数组元素的平均值。 |
ndarray.var([axis,dtype,out,ddof,keepdims]) | 沿给定轴返回数组元素的方差。 |
ndarray.std([axis,dtype,out,ddof,keepdims]) | 返回给定轴上的数组元素的标准偏差。 |
ndarray.argmax([axis,out]) | 沿着给定轴的最大值的返回索引。 |
ndarray.min([axis,out,keepdims]) | 沿给定轴返回最小值。 |
ndarray.argmin([axis,out]) | 沿着给定轴的最小值的返回索引。 |
››› x = np.random.randint(10, size=6).reshape(2,3) ››› x array([[3, 7, 0], [7, 1, 3]]) ››› np.sum(x) 21 ››› np.sum(x, axis=0) array([10, 8, 3]) ››› np.sum(x, axis=1) array([10, 11]) ››› np.argmax(x) 1 ››› np.argmax(x, axis=0) array([1, 0, 1], dtype=int64) ››› np.argmax(x, axis=1) array([1, 0], dtype=int64)