Python——獲取矩陣均值


當需要獲取矩陣元素的均值時,需要在匯入環境中從“Numpy”包中使用“mean”方法。

示例

以下是演示操作:

import numpy as np

my_matrix = np.matrix('[24, 41; 35, 25]')
print("The matrix is : " )
print(my_matrix)

my_result = my_matrix.mean()

print("The result is : ")
print(my_result)

輸出

The matrix is :
[[24 41]
[35 25]]
The result is :
31.25

說明

  • 將必需的包匯入環境。

  • 使用 Numpy 包建立一個矩陣。

  • 在控制檯中顯示它。

  • 使用“mean”方法確定矩陣的均值。

  • 將其分配給一個變數。

  • 將其作為輸出顯示在控制檯中。

更新時間: 2021-09-13

188 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.