如何用函数求python非方阵矩阵内所有元素的N次方!非常感谢~
2条回答 默认 最新
关注可以原生Python实现
def matrix_power(matrix, power): result = [] for row in matrix: new_row = [] for element in row: new_row.append(element ** power) result.append(new_row) return result你还可以借助第三方库函数,比如numpy
import numpy as np matrix = [[1, 2, 3], [4, 5], [6, 7, 8, 9]] power = 2 result = np.power(matrix, power)本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报