Python | sympy。矩阵()。col_insert()

原文:https://www . geesforgeks . org/python-sympy-matrix-col _ insert/

借助**Matrix().col_insert()**方法,我们可以在维数为 nxm 的矩阵中插入一列,其中插入列的维数为 nx1。

语法: Matrix().col_insert() 返回:返回新矩阵。

示例#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)

输出:

矩阵([[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)

输出:

矩阵([[1,2,13],[2,1,24]])