Converts a tensor to a matrix.