<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def psnr_stack(data1, data2, metric=np.mean, method='starck'):
 r"""Peak Signa-to-Noise for stack of images This method calculates the PSNRs for two stacks of 2D arrays. By default the metod returns the mean value of the PSNRs, but any other metric can be used. Parameters data1 : np.ndarray Stack of images, 3D array data2 : np.ndarray Stack of recovered images, 3D array method : str {'starck', 'wiki'}, optional PSNR implementation, default ('starck') metric : function The desired metric to be applied to the PSNR values (default is 'np.mean') Returns ------- float metric result of PSNR values Raises ------ ValueError For invalid input data dimensions Examples -------- 12.041199826559248 """


    if data1.ndim != 3 or data2.ndim != 3:
        raise ValueError('Input data must be a 3D np.ndarray')

    return metric([psnr(i, j, method=method) for i, j in
                  zip(data1, data2)])