Use Python's Scipy DCT-II to do 2D or ND DCT
Basically, the following does the trick:
import numpy as np
from scipy.fftpack import dct, idct
# Lets create a 3D array and fill it with some values
a = np.random.rand(3,3,3)
b = dct(dct(dct(a).transpose(0,2,1)).transpose(1,2,0)).transpose(1,2,0).transpose(0,2,1)