Converts a matrix to a tensor.