Tensor初始化:
-
Directly from data:
Tensors can be created directly from data. The data type is automatically inferred.
data = [[1, 2],[3, 4]] x_data = torch.tensor(data)
-
From a NumPy array Tensors can be created from NumPy arrays
np_array = np.array(data) x_np = torch.from_numpy(np_array)
-
Attributes of a Tensor
Tensor attributes describe their shape, datatype, and the device on which they are stored.
-
tensor operations, including arithmetic, linear algebra, matrix manipulation (transposing, indexing, slicing), sampling and more are comprehensively describedhttps://pytorch.org/docs/stable/torch.html
-
Bridge with NumPy
t = torch.ones(5)
n = t.numpy()
n = np.ones(5) t = torch.from_numpy(n)