Python SymPy Module:
SymPy is a Python symbolic mathematics library. It aims to be a full-featured computer algebra system (CAS) while keeping the code as basic(simple) as possible in order to be understandable and easily expandable. SymPy is entirely written in Python. SymPy is simple to use because it only depends on mpmath, a pure Python library for arbitrary floating-point arithmetic.
Rational and Integer are the numerical types defined by SymPy. A rational number is represented by the Rational class as a pair of two Integers, numerator and denominator, therefore Rational(1, 2) is 1/2, Rational(3, 2) is 3/2, and so on. Integer numbers are represented by the Integer class.
SymPy uses mpmath in the background, allowing it to execute arbitrary-precision arithmetic computations. Some special constants, such as exp, pi, and oo (Infinity), are thus considered as symbols and can be evaluated with arbitrary precision.
Installation:
pip install sympy
Python sympy.Matrix.row_del() Method:
We can delete the rows of a matrix using the sympy.Matrix.row_del() function.
Syntax:
sympy.Matrix().row_del()
Return Value:
A new matrix after the deletion of the row is returned by the Matrix.row_del() function.
sympy.Matrix.row_del() Method in Python
For 2-Dimensional (2D) Matrix
Approach:
- Import all the methods from sympy using the import keyword
- Create a 2-Dimensional(2D) matrix using the Matrix() function by passing some random 2D matrix as an argument to it and store it in a variable.
- Apply row_del() function on the above-given matrix by passing the row number as an argument to it
to delete the values of the specified row. - Here it deletes the zero(0th) row.
- Print the given matrix after deleting the zero(0th) row.
- The Exit of the Program.
Below is the implementation:
# Import all the methods from sympy using the import keyword from sympy import * # Create a 2-Dimensional(2D) matrix using the Matrix() function by passing some random # 2D matrix as an argument to it and store it in a variable. gvn_matrx = Matrix([[3, 5], [6, 8]]) # Apply row_del() function on the above given matrix by passing the row number as an # argument to it to delete the values of the specified row. # Here it deletes the zero(0th) row. gvn_matrx.row_del(0) # Print the given matrix after deleting the zero(0th) row. print("The given matrix after deleting the zero(0th) row:") print(gvn_matrx)
Output:
The given matrix after deleting the zero(0th) row: Matrix([[6, 8]])
For 3-Dimensional (3D) Matrix
Approach:
- Import all the methods from sympy using the import keyword
- Create a 3-Dimensional(3D) matrix using the Matrix() function by passing some random 3D matrix as an argument to it and store it in a variable.
- Apply row_del() function on the above-given matrix by passing the row number as an argument to it
to delete the values of the specified row. - Here it deletes the 1st row.
- Print the given matrix after deleting the 1st row.
- The Exit of the Program.
Below is the implementation:
# Import all the methods from sympy using the import keyword from sympy import * # Create a 3-Dimensional(3D) matrix using the Matrix() function by passing some random # 3D matrix as an argument to it and store it in a variable. gvn_matrx = Matrix([[1, 6, 10], [8, 7, 5], [3, 2, 9]]) # Apply row_del() function on the above given matrix by passing the row number as # an argument to it to delete the values of the specified row. # Here it deletes the 1st row gvn_matrx.row_del(1) # Print the given matrix after deleting the 1st row print("The given matrix after deleting the 1st row:") print(gvn_matrx)
Output:
The given matrix after deleting the 1st row: Matrix([[1, 6, 10], [3, 2, 9]])