import numpy as np

创建 matr1 矩阵

matr1 = np.zeros((8, 8))

设置 1、3、5、7 行和 2、4、6 列的元素为 1

matr1[0::2, :] = 1 matr1[:, 1::2] = 1

创建随机整数数组 arr

arr = np.random.randint(1, 20, size=(8, 2))

将 arr 转为矩阵 matr2

matr2 = np.matrix(arr)

计算 matr1 和 matr2 的矩阵乘积

result = np.dot(matr1, matr2)

print(result)

Python NumPy矩阵运算:创建矩阵、随机数组并进行矩阵乘积

原文地址: https://www.cveoy.top/t/topic/bnhO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录