np.maximum ()
傳入兩個列表,維度一致,不一致時,進行廣播。逐一比較大小,取較大值。
np.
max:(a, axis=
none, out=
none, keepdims=
false)
求序列的最值
最少接收乙個引數
axis:預設為列向(也即 axis=0),axis = 1 時為行方向的最值;
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,返回乙個新的陣列
a = np.array([[1, np.nan], [3, 4]])
aout[17]:
array([[ 1., nan],
[ 3., 4.]])
np.nanmean(a)
2.6666666666666665
#求所有元素均值,但去除nan,個數也不包括nan
np.nanmean(a, axis=0)
out[18]: array([ 2., 4.])
#沿著0軸 求均值
np.nanmean(a, axis=1)
array([ 1., 3.5])
#沿著1軸求均值
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
np.full((3,3),5,dtype='float32')
out[23]:
array([[ 5., 5., 5.],
[ 5., 5., 5.],
[ 5., 5., 5.]], dtype=float32)
Numpy使用記錄
np.where condition,x,y 若x,y是值,那麼就是condition正確,陣列的值變為x若不正確則數值變為y np.where condition 返回滿足條件的值的x,y值。np.amin shuzu,0 1 一維陣列找最小值,二維陣列需要指定行或列,1是找行最小的,0是找列最小...
numpy函式記錄
功能 產生size個離散均勻分布的整數,這些整數大於等於low,小於high。預設high是none,如果只有low,那範圍就是 0,low 如果有high,範圍就是 low,high n 3a np.random.randint 20,40,n,2 astype np.float32 b np.r...
numpy基本使用
參考文獻 官方幫助文件 numpy v1.12 manual csdn numpy之四 高階索引和索引技巧 from numpy import definit array print 建立一維陣列 a arange 5 print a print a.dtype 顯示陣列中的資料型別 print a...