创建矩阵及矩阵之间的运算

import numpy as np

# 一、创建矩阵
# 1、mat函数
A = np.mat([[1, 0, 1, 0],
            [-1, 2, 0, 1],
            [1, 0, 4, 1],
            [-1, -1, 2, 0]])
print(A)
"""
[[ 1  0  1  0]
 [-1  2  0  1]
 [ 1  0  4  1]
 [-1 -1  2  0]]
"""
# 方法二
B = np.mat('1 0 0 0;0 1 0 0;-1 2 1 0;1 1 0 1')
print(B)
"""
[[ 1  0  0  0]
 [ 0  1  0  0]
 [-1  2  1  0]
 [ 1  1  0  1]]
"""
# 1、matrix函数
# np.matrix()

# 3.bmat函数:通过分块矩阵创建大矩阵
A = np.mat([[1, 1], [1, 1]])
B = np.mat([[2, 2], [2, 2]])
C = np.mat([[3, 3], [3, 3]])
D = np.mat([[4, 4], [4, 4]])
big_mat = np.bmat([[A, B], [C, D]])
print(big_mat)
"""
[[1 1 2 2]
 [1 1 2 2]
 [3 3 4 4]
 [3 3 4 4]]
"""

# 矩阵运算
A = np.mat([[1, 1], [1, 1]])
B = np.mat([[2, 2], [3, 3]])
print(A*3)
"""
[[3 3]
 [3 3]]
"""
print(A+B)
"""
[[3 3]
 [4 4]]
"""
print(A*B)
"""
[[5 5]
 [5 5]]
"""

# 矩阵对应元素相乘
print(np.multiply(A,B))
"""
[[2 2]
 [3 3]]
"""

矩阵特有的属性:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值