Created
September 11, 2020 12:23
-
-
Save e96031413/addb24a8dab4a8ba405015a42a5a7d9e to your computer and use it in GitHub Desktop.
some pytorch and numpy usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# torch.unsqueeze(1)可以新增shape | |
example: | |
x_val = torch.Size([10000, 28, 28]) | |
x_val = x_val.unsqueeze(1) | |
# [out] torch.Size([10000, 1, 28, 28]) | |
# the ToTensor method to convert images into PyTorch tensors. | |
# passed the transformer function to the dataset class. This way, data | |
# transformation will happen on-the-fly. This is a useful technique for large datasets that | |
# cannot be loaded into memory all at once. | |
img_t = torch.randn(3, 5, 5) # shape [channels, rows, columns] | |
batch_t = torch.randn(2, 3, 5, 5) # shape [batch, channels, rows, columns] | |
torch.Size([5, 5]), # shape ['rows', 'columns'] | |
# np.reshape不改變原本的shape | |
# np.resize改變原本的shape | |
# np.hstack()、np.vstack()作concatenating arrays | |
# Broadcasting can add a scalar to a vector |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment