input: Write a function to define a class in Python that performs various matrix operations like addition, subtraction, multiplication, and transpose. The class should include methods for initializing the matrix, adding another matrix, subtracting another matrix, multiplying with another matrix, and transposing the matrix. The function should return the modified matrix after each operation.
  assert Matrix(2, 2, [1, 2, 3, 4]).add(Matrix(2, 2, [5, 6, 7, 8]))==[[6, 8], [10, 12]]
  assert Matrix(2, 2, [1, 2, 3, 4]).sub(Matrix(2, 2, [5, 6, 7, 8]))==[[-4, -4], [-4, -4]]
  assert Matrix(2, 2, [1, 2, 3, 4]).mul(Matrix(2, 2, [5, 6, 7, 8]))==[[19, 22], [43, 50]]
  assert Matrix(2, 2, [1, 2, 3, 4]).transpose()==[[1, 3], [2, 4]]
  assert Matrix(0, 0, []).add(Matrix(0, 0, []))==[]
  assert Matrix(0, 0, []).sub(Matrix(0, 0, []))==[]
  assert Matrix(0, 0, []).mul(Matrix(0, 0, []))==[]
  assert Matrix(0, 0, []).transpose()==[]
output: class Matrix:
      def __init__(self, rows, cols, data):
          self.rows = rows
          self.cols = cols
          self.data = data
  
      def add(self, other):
          if self.rows != other.rows or self.cols != other.cols:
              raise ValueError("Matrices must be of the same dimensions")
          result = [[self.data[i][j] + other.data[i][j] for j in range(self.cols)] for i in range(self.rows)]
          return result
  
      def sub(self, other):
          if self.rows != other.rows or self.cols != other.cols:
              raise ValueError("Matrices must be of the same dimensions")
          result = [[self.data[i][j] - other.data[i][j] for j in range(self.cols)] for i in range(self.rows)]
          return result
  
      def mul(self, other):
          if self.cols != other.rows:
              raise ValueError("Number of columns in the first matrix must be equal to the number of rows in the second matrix")
          result = [[sum(self.data[i][k] * other.data[k][j] for k in range(self.cols)) for j in range(other.cols)] for i in range(self.rows)]
          return result
  
      def transpose(self):
          result = [[self.data[j][i] for j in range(self.rows)] for i in range(self.cols)]
          return result