numpy使用记录

来源:互联网 发布:python 迭代器的方法 编辑:程序博客网 时间:2024/06/03 20:29
np.maximum ()

传入两个列表,维度一致,不一致时,进行广播。逐一比较大小,取较大值。

np.max:(a, axis=None, out=None, keepdims=False)

求序列的最值
最少接收一个参数
axis:默认为列向(也即 axis=0),axis = 1 时为行方向的最值;

np.where

np.where(condition,x,y)

condition会得到索引,满足条件,填入数组x在该索引处的值,不满足取y在该索引处的值

new_array=np.where(this_chan == np.min(this_chan),np.nan, this_chan)

在this_chan这个数组,最小值的地方换成nan,返回一个新的数组

np.nanmean

a = np.array([[1, np.nan], [3, 4]])aOut[17]: array([[  1.,  nan],       [  3.,   4.]])np.nanmean(a)    2.6666666666666665#求所有元素均值,但去除nan,个数也不包括nannp.nanmean(a, axis=0)Out[18]: array([ 2.,  4.])#沿着0轴  求均值np.nanmean(a, axis=1)    array([ 1.,  3.5])#沿着1轴求均值

np.outer

def outer(a, b, out=None):    """    Compute the outer product of two vectors.    Given two vectors, ``a = [a0, a1, ..., aM]`` and    ``b = [b0, b1, ..., bN]``,    the outer product [1]_ is::      [[a0*b0  a0*b1 ... a0*bN ]       [a1*b0    .       [ ...          .       [aM*b0            aM*bN ]]    Parameters    ----------    a : (M,) array_like        First input vector.  Input is flattened if        not already 1-dimensional.    b : (N,) array_like        Second input vector.  Input is flattened if        not already 1-dimensional.    out : (M, N) ndarray, optional        A location where the result is stored        .. versionadded:: 1.9.0    Returns    -------    out : (M, N) ndarray