Skip to content

Instantly share code, notes, and snippets.

@monk1337
Created June 7, 2018 15:25
Show Gist options
  • Save monk1337/80b71de3a7f4dd7df47976039eecf13f to your computer and use it in GitHub Desktop.
Save monk1337/80b71de3a7f4dd7df47976039eecf13f to your computer and use it in GitHub Desktop.
import torch
print('two dim')
print(torch.rand(2,5))
# output:
# two dim
# tensor([[ 0.2495, 0.2948, 0.5486, 0.5077, 0.1657],
# [ 0.4142, 0.8142, 0.8635, 0.8827, 0.7176]])
print('three dim')
print(torch.rand(2,5,2))
# three dim
# tensor([[[ 0.0122, 0.9785],
# [ 0.3095, 0.7975],
# [ 0.5895, 0.7899],
# [ 0.7017, 0.5403],
# [ 0.9211, 0.9879]],
# [[ 0.1303, 0.5413],
# [ 0.2247, 0.4649],
# [ 0.3728, 0.0710],
# [ 0.9711, 0.7004],
# [ 0.2834, 0.0401]]])
print(torch.rand(5,2,2))
# tensor([[[ 0.3401, 0.0993],
# [ 0.9443, 0.0131]],
# [[ 0.4662, 0.7676],
# [ 0.6883, 0.4816]],
# [[ 0.9938, 0.4626],
# [ 0.3472, 0.4274]],
# [[ 0.7472, 0.0985],
# [ 0.4303, 0.6550]],
# [[ 0.0768, 0.9462],
# [ 0.9294, 0.6774]]])
print('four dim')
print(torch.rand(2,3,1,3))
# forth dim
# tensor([[[[ 0.6665, 0.7465, 0.2405]],
# [[ 0.0075, 0.9944, 0.1865]],
# [[ 0.3335, 0.5502, 0.3171]]],
# [[[ 0.0157, 0.8239, 0.2782]],
# [[ 0.6246, 0.8409, 0.7489]],
# [[ 0.8017, 0.9434, 0.8381]]]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment