python矩阵相乘例题_Python程序将两个矩阵相乘。

该博客演示了如何在Python中通过用户输入创建两个矩阵,并计算它们的乘积。使用嵌套循环来遍历并计算矩阵元素,最后展示乘法运算后的结果矩阵。
摘要由CSDN通过智能技术生成

给定两个用户输入矩阵。我们的任务是显示两个矩阵的加法。在这些问题中,我们综合使用嵌套列表。

算法Step1: input two matrix.

Step 2: nested for loops to iterate through each row and each column.

Step 3: take one resultant matrix which is initially contains all 0. Then we multiply each row elements of first matrix with each elements of second matrix, then add all multiplied value. That is the value of resultant matrix.

范例程式码# Program to multiply two matrices

A=[]

n=int(input("Enter N for N x N matrix: "))

print("Enter the element ::>")

for i in range(n):

row=[]                                      #temporary list to store the row

for j in range(n):

row.append(int(input()))           #add the input to row list

A.append(row)                      #add the row to the list

print(A)

# [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

#Display the 2D array

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值