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”方法確定矩陣的均值。
將其分配給一個變數。
將其作為輸出顯示在控制檯中。
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP