<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def matrix_to_timeseries( image, matrix, mask=None ):
 """ converts a matrix to a ND image. ANTsR function: `matrix2timeseries` Arguments --------- image: reference ND image matrix: matrix to convert to image mask: mask image defining voxels of interest Returns ------- ANTsImage Example ------- """


    if mask is None:
        mask = temp[0]*0 + 1
    temp = matrix_to_images( matrix, mask )
    newImage = utils.list_to_ndimage( image, temp)
    iio.copy_image_info( image, newImage)
    return(newImage)