def dct_matrix(rows, cols, unitary=True):
 rval = numpy.zeros((rows, cols))
 col_range = numpy.arange(cols)
 scale = numpy.sqrt((2.0 / cols))
 for i in xrange(rows):
  rval[i] = (numpy.cos((((i * ((col_range * 2) + 1)) / (2.0 * cols)) * numpy.pi)) * scale)
 if unitary:
  rval[0] *= numpy.sqrt(0.5)
 return rval

def dct_matrix ( rows , cols , unitary = True ) : rval = numpy . zeros ( ( rows , cols ) ) col_range = numpy . arange ( cols ) scale = numpy . sqrt ( ( 2.0 / cols ) ) for i in xrange ( rows ) : rval [ i ] = ( numpy . cos ( ( ( ( i * ( ( col_range * 2 ) + 1 ) ) / ( 2.0 * cols ) ) * numpy . pi ) ) * scale ) if unitary : rval [ 0 ] *= numpy . sqrt ( 0.5 ) return rval
return a matrix implementing a discrete cosine transform .