<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def timeseries_to_matrix( image, mask=None ):
 """ Convert a timeseries image into a matrix. ANTsR function: `timeseries2matrix` Arguments --------- image : image whose slices we convert to a matrix. E.g. a 3D image of size x by y by z will convert to a z by x*y sized matrix mask : ANTsImage (optional) image containing binary mask. voxels in the mask are placed in the matrix Returns ------- ndarray array with a row for each image shape = (N_IMAGES, N_VOXELS) Example ------- """

    temp = utils.ndimage_to_list( image )
    if mask is None:
        mask = temp[0]*0 + 1
    return image_list_to_matrix( temp, mask )