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.



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

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

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.