numpy中的mean()函數


mean() 函數定義:
numpy.mean(a, axis, dtype, out,keepdims )

mean()函數功能:求取均值
經常操作的參數為axis,以m * n矩陣舉例:

axis 不設置值,對 mn 個數求均值,返回一個實數
axis = 0:壓縮行,對各列求均值,返回 1
n 矩陣
axis = 1 :壓縮列,對各行求均值,返回 m *1 矩陣

舉例:

>>>  import numpy as np

>>> num1 = np.array([[1,2,3],[2,3,4],[3,4,5],[4,5,6]])
>>> now2 = np.mat(num1)
>>> now2
matrix([[1, 2, 3],
        [2, 3, 4],
        [3, 4, 5],
        [4, 5, 6]])


>>> np.mean(now2) # 對所有元素求均值
3.5


>>> np.mean(now2,0) # 壓縮行,對各列求均值
matrix([[ 2.5,  3.5,  4.5]])


>>> np.mean(now2,1) # 壓縮列,對各行求均值
matrix([[ 2.],
        [ 3.],
        [ 4.],
        [ 5.]])


參考:http://blog.csdn.net/taotiezhengfeng/article/details/72397282


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM