1. 程式人生 > >np.random.uniform

np.random.uniform

numpy.random.uniform介紹:

函式原型:  numpy.random.uniform(low,high,size)

功能:從一個均勻分佈[low,high)中隨機取樣,注意定義域是左閉右開,即包含low,不包含high.

引數介紹:           low: 取樣下界,float型別,預設值為0;     high: 取樣上界,float型別,預設值為1;     size: 輸出樣本數目,為int或元組(tuple)型別,例如,size=(m,n,k), 則輸出m*n*k個樣本,預設時輸出1個值。

返回值:ndarray型別,其形狀和引數size中描述一致。

這裡順便說下ndarray型別,表示一個N維陣列物件,其有一個shape(表維度大小)和dtype(說明陣列資料型別的物件),使用zeros和ones函式可以建立資料全0或全1的陣列,原型:

    numpy.ones(shape,dtype=None,order='C'), 其中,shape表陣列形狀(m*n),dtype表型別,order表是以C還是fortran形式存放資料。