# Python sympy.Matrix.col_del() Method

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.col_del() Method:

We can delete the columns of a matrix using the sympy.Matrix.col_del() function.

Syntax:

 sympy.Matrix().col_del()

Return Value:

A new matrix after the deletion of the column is returned by the Matrix.col_del() function.

## sympy.Matrix.col_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 col_del() function on the above-given matrix by passing the column number as an argument to it
to delete the values of the specified column.
• Here it deletes the zero(0th) column.
• Print the given matrix after deleting the zero(0th) column.
• 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 col_del() function on the above given matrix by passing the column number as an argument to it
# to delete the values of the specified column.
# Here it deletes the zero(0th) column.
gvn_matrx.col_del(0)

# Print the given matrix after deleting the zero(0th) column.
print("The given matrix after deleting the zero(0th) column:")
print(gvn_matrx)


Output:

The given matrix after deleting the zero(0th) column:
Matrix([[5], [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 col_del() function on the above-given matrix by passing the column number as an argument to it
to delete the values of the specified column.
• Here it deletes the 1st column.
• Print the given matrix after deleting the 1st column.
• 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 col_del() function on the above given matrix by passing the column number as an argument to it
# to delete the values of the specified column.
# Here it deletes the 1st column.
gvn_matrx.col_del(1)

# Print the given matrix after deleting the 1st column
print("The given matrix after deleting the 1st column:")
print(gvn_matrx)


Output:

The given matrix after deleting the 1st column:
Matrix([[1, 10], [8, 5], [3, 9]])