input: def matrix_operations():
      """
      Develop a class in Python to perform various matrix operations like addition, subtraction, multiplication and transpose.
      The class should be able to initialize a matrix, print the matrix, add another matrix, subtract another matrix, multiply by another matrix, and transpose the matrix.
      
      Example:
      m1 = Matrix(2, 2, [1, 2, 3, 4])
      m2 = Matrix(2, 2, [5, 6, 7, 8])
      m1.add(m2)
      print(m1)  # Output: "6 8 \n10 12 \n"
      """
output:     
      class Matrix:
          def __init__(self, rows, cols, data):
              self.rows = rows
              self.cols = cols
              self.data = data
  
          def __str__(self):
              return '\n'.join([' '.join(map(str, self.data[i*self.cols:(i+1)*self.cols])) for i in range(self.rows)]) + '\n'
  
          def add(self, other):
              if self.rows != other.rows or self.cols != other.cols:
                  raise ValueError("Matrices must have the same dimensions for addition")
              self.data = [self.data[i] + other.data[i] for i in range(len(self.data))]
  
          def subtract(self, other):
              if self.rows != other.rows or self.cols != other.cols:
                  raise ValueError("Matrices must have the same dimensions for subtraction")
              self.data = [self.data[i] - other.data[i] for i in range(len(self.data))]
  
          def multiply(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 = []
              for i in range(self.rows):
                  for j in range(other.cols):
                      sum = 0
                      for k in range(self.cols):
                          sum += self.data[i*self.cols + k] * other.data[k*other.cols + j]
                      result.append(sum)
              self.data = result
              self.cols = other.cols
  
          def transpose(self):
              new_data = []
              for j in range(self.cols):
                  for i in range(self.rows):
                      new_data.append(self.data[i*self.cols + j])
              self.data = new_data
              self.rows, self.cols = self.cols, self.rows
  