Wednesday, July 3, 2024
HomeLanguagesPythonPython | sympy.Matrix().col_insert()

Python | sympy.Matrix().col_insert()

With the help of Matrix().col_insert() method, we can insert a column in a matrix having dimension nxm, where dimension of inserted column is nx1.

Syntax : Matrix().col_insert()
Return : Return a new matrix.

Example #1 :
In this example, we are able to insert a column in a matrix by using Matrix().col_insert() method.




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


Output :

Matrix([[1, 3, 2], [2, 4, 1]])

Example #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)


Output :

Matrix([[1, 2, 13], [2, 1, 24]])

Calisto Chipfumbu
Calisto Chipfumbuhttp://cchipfumbu@gmail.com
I have 5 years' worth of experience in the IT industry, primarily focused on Linux and Database administration. In those years, apart from learning significant technical knowledge, I also became comfortable working in a professional team and adapting to my environment, as I switched through 3 roles in that time.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments