def get_diff_mat(dim, axis):
 val_arr = []
 row_arr = []
 col_arr = []
 for i in range(dim):
  val_arr.append(1.0)
  row_arr.append(i)
  col_arr.append(i)
  if (i > 0):
   val_arr.append((-1.0))
   row_arr.append(i)
   col_arr.append((i - 1))
 mat = sp.coo_matrix((val_arr, (row_arr, col_arr)), (dim, dim)).tocsc()
 if (axis == 0):
  return mat
 else:
  return mat.T

def get_diff_mat ( dim , axis ) : val_arr = [ ] row_arr = [ ] col_arr = [ ] for i in range ( dim ) : val_arr . append ( 1.0 ) row_arr . append ( i ) col_arr . append ( i ) if ( i > 0 ) : val_arr . append ( ( - 1.0 ) ) row_arr . append ( i ) col_arr . append ( ( i - 1 ) ) mat = sp . coo_matrix ( ( val_arr , ( row_arr , col_arr ) ) , ( dim , dim ) ) . tocsc ( ) if ( axis == 0 ) : return mat else : return mat . T
return a sparse matrix representation of first order difference operator .