Python| sympy.Matrix().col_insert()
借助Matrix().col_insert()
方法,我们可以在维度为 nxm 的矩阵中插入一列,其中插入列的维度为 nx1。
Syntax : Matrix().col_insert()
Return : Return a new matrix.
示例 #1:
在这个例子中,我们可以使用Matrix().col_insert()
方法在矩阵中插入一列。
# Import all the methods from sympy
from sympy import *
# Make a matrix
gfg_mat = Matrix([[1, 2], [2, 1]])
# use the col_insert() method for matrix
new_mat = gfg_mat.col_insert(1, Matrix([[3], [4]]))
print(new_mat)
输出 :
Matrix([[1, 3, 2], [2, 4, 1]])
示例 #2:
# Import all the methods from sympy
from sympy import *
# Make a matrix
gfg_mat = Matrix([[1, 2], [2, 1]])
# use the col_insert() method for matrix
new_mat = gfg_mat.col_insert(2, Matrix([[13], [24]]))
print(new_mat)
输出 :
Matrix([[1, 2, 13], [2, 1, 24]])