<jupyter_start><jupyter_text>01. TensorsTensors are similar to NumPy's ndarrays, with the addition being that Tensors can also be used on a GPU to accelerate computing.<jupyter_code>from __future__ import print_function
import torch<jupyter_output><empty_output><jupyter_text>Note: An uninitialized matrix is declared, but does not contain definite known values before it is used. When an uninitialized matrix is created, whatever values were in the allocated memory at the time will appear as the initial values.<jupyter_code># construct a 5x3 matrix, uninitialized:
x = torch.empty(5, 3)
print(x)
# construct a 5x3 randomly initialized matrix:
x = torch.rand(5, 3)
print(x)
# construct a matrix filled zeros and of dtype long:
x = torch.zeros(5, 3, dtype=torch.long)
print(x)
# construct a tensor directly from data:
x = torch.tensor([5.5, 3])
print(x)
# create a tensor based on an existing tensor.
# these methods will reuse properties of the input tensor, e.g. dtype, unless new values are provided by user.
x = x.new_ones(5, 3, dtype=torch.double) # new_* methods take in sizes
print(x)

y = torch.randn_like(x, dtype=torch.float) # override dtype, result has the same size
print(y)
# get its size:
print(x.size())
print(y.size())<jupyter_output>torch.Size([5, 3])
torch.Size([5, 3])
{'fraction_non_alphanumeric': 0.09542280837858805, 'fraction_numerical': 0.016291698991466253, 'mean_word_length': 5.417910447761194, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '257542', 'license': 'MIT', 'n_tokens_mistral': 417, 'n_tokens_neox': 408, 'n_words': 164, 'path': '01-basics/01-tensors.ipynb', 'repo_name': 'shuhua-wang/pytorch-tutorials', 'size': '1289'}