import torch # Create a tensor with some random values x = torch.randn(3, 4) # Use _values to get a new tensor with just the raw data values = x._values() print(values)
import torch # Create a tensor and calculate its gradient x = torch.randn(3, 4, requires_grad=True) y = x * 2 z = y.mean() # Use _values to get a new tensor without the gradient information values = x._values() print(values)In this example, we create a tensor `x` with dimensions 3x4 and set the `requires_grad` flag to `True` in order to calculate gradients later on. We perform some calculations using `x`, then use `_values` to get a new tensor `values` that does not contain the gradient information. Based on the syntax and the use of the `torch` library, we can determine that these examples use PyTorch as the package library.