Loading...
Given a PyTorch tensor, extract and return its key attributes.
Understanding tensor attributes is crucial for debugging and ensuring tensors are compatible for operations. Every tensor has a shape, data type, and device.
Write a function get_tensor_info(tensor) that returns a dictionary containing the tensor's shape (as a list), dtype (as a string), and device (as a string).
Return a dictionary with keys: "shape", "dtype", "device".
torch.rand(2, 3)
{"shape": [2, 3], "dtype": "torch.float32", "device": "cpu"}We access tensor.shape, tensor.dtype, and tensor.device attributes