Converts a matrix to an array.