Method ConvertToString
ConvertToString(Tensor, ScalarType)
Method that converts a tensor into a string. The string value is in a Python-like syntax. For example, a 2x2 tensor can be created with the following values: "[[1, 2], [3, 4]]".
public static string ConvertToString(torch.Tensor tensor, torch.ScalarType scalarType)
Parameters
tensor
torch.TensorThe tensor to convert.
scalarType
torch.ScalarTypeThe scalar type of the tensor.
Returns
- string
A string representation of the tensor.
Remarks
The TorchSharp library does not provide a generic method to extract the data from the tensor as an object. Thus, we use the provided TorchSharp.torch.ScalarType as the expected .NET data type to extract the data from the tensor. The data is then passed to the PythonDataHelper class to format the data into the appropriate string representation for the given data type.
Exceptions
- ArgumentException
Thrown when the TorchSharp.torch.ScalarType is not supported for converting to .NET data type