Monday, February 9, 2026
HomeLanguagesPython | sympy.Matrix().row_insert()

Python | sympy.Matrix().row_insert()

With the help of Matrix().row_insert() method, we can insert a row in a matrix having dimension nxm, where dimension of inserted row is 1xm.

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

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




# Import all the methods from sympy
from sympy import *
  
# Make a matrix
gfg_mat = Matrix([[1, 2], [2, 1]])
  
# use the row_insert() method for matrix
new_mat = gfg_mat.row_insert(1, Matrix([[3, 4]]))
   
print(new_mat)


Output :

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

Example #2 :




# Import all the methods from sympy
from sympy import *
  
# Make a matrix
gfg_mat = Matrix([[1, 2], [2, 1]])
  
# use the row_insert() method for matrix
new_mat = gfg_mat.row_insert(2, Matrix([[13, 24]]))
   
print(new_mat)


Output :

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32493 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6866 POSTS0 COMMENTS
Nicole Veronica
11991 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12086 POSTS0 COMMENTS
Shaida Kate Naidoo
7001 POSTS0 COMMENTS
Ted Musemwa
7241 POSTS0 COMMENTS
Thapelo Manthata
6953 POSTS0 COMMENTS
Umr Jansen
6939 POSTS0 COMMENTS