All problems
DCT Apply
Problem
Apply the orthonormal DCT-II transform to vector x of length n:
out[k] = alpha_k * sum_i x[i] * cos(pi * (2i + 1) * k / (2n))
with alpha_0 = sqrt(1/n) and alpha_k = sqrt(2/n) for k > 0.
Hint
The DCT is a real orthogonal transform; the k = 0 coefficient is the mean times sqrt(n).
Test cases
case 1
in: [[1,0,0,0]]
expected: [0.5,0.6532814824381883,0.5,0.27059805007309856]
case 2
in: [[1,1,1,1]]
expected: [2,0,0,0]
case 3
in: [[1,2,3,4]]
expected: [5,-2.230442497387663,0,-0.15851266778110815]
case 4
in: [[1,0]]
expected: [0.7071067811865476,0.7071067811865476]
Starter codePython
def dct_apply(x):
# Your code here
pass4 test cases · run your code against them in the editor