import torch
a = torch.ones(3)
print(f"a: {a}")
print(f"d.shape: {a.shape}")
print(f"a.dim: {a.dim()}")
print(f"a.dtype: {a.dtype}")a: tensor([1., 1., 1.])
d.shape: torch.Size([3])
a.dim: 1
a.dtype: torch.float32
Kunlei Lian
June 24, 2024
import torch
a = torch.ones(3)
print(f"a: {a}")
print(f"d.shape: {a.shape}")
print(f"a.dim: {a.dim()}")
print(f"a.dtype: {a.dtype}")a: tensor([1., 1., 1.])
d.shape: torch.Size([3])
a.dim: 1
a.dtype: torch.float32
tensor([[[0., 0., 0., 0.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]],
[[0., 0., 0., 0.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]]])
b = torch.tensor([
[1.0, 2.0],
[2.0, 4.0],
[3.0, 6.0]
])
print(f"b: {b}")
print(f"b.shape: {b.shape}")
print(f"b.dim: {b.dim()}")
print(f"b.dtype: {b.dtype}")
b: tensor([[1., 2.],
[2., 4.],
[3., 6.]])
b.shape: torch.Size([3, 2])
b.dim: 2
b.dtype: torch.float32
image_gray_naive = image_t.mean(dim=-3)
batch_gray_naive = batch_t.mean(dim=-3)
image_gray_naive.shape, batch_gray_naive.shape(torch.Size([5, 5]), torch.Size([2, 5, 5]))
tensor([[-0.2332, 0.3938, -0.3767, 0.5071, -0.7080],
[ 0.3150, -0.0869, 0.3916, -0.1328, 0.2715],
[-0.1035, -0.4130, 0.1052, -0.1838, -0.2134],
[-0.4150, -0.0241, 0.7105, -0.9059, 0.5978],
[ 0.2595, -0.3144, 0.1214, -0.4523, 1.3808]])
tensor([[[-0.2599, -0.2635, 0.0538, 0.3724, 0.0113],
[-1.0019, -0.4934, 0.3516, -0.5659, -0.2056],
[-0.2812, -1.2758, 0.8221, -0.3691, -0.9555],
[ 0.7293, -0.8631, 0.6655, -0.1749, 0.6374],
[-0.9790, -0.0309, -0.0135, 0.6081, 0.1212]],
[[-0.6569, -0.2976, 0.4795, -0.3773, 0.5667],
[-0.3750, 0.9626, 1.4857, 0.1569, -0.3597],
[-0.8239, -0.8770, 0.1830, -1.0730, 0.1203],
[-0.1412, -0.3397, 0.0377, -0.4546, 0.1984],
[ 0.7905, 0.2810, -0.8559, 0.1058, 0.4775]]])
tensor([[[0.2126]],
[[0.7152]],
[[0.0722]]])
torch.Size([10, 2])
/var/folders/8h/0198_l7s2vj1nwsk_h331bc00000gn/T/ipykernel_80062/2923139482.py:2: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
points.storage()
4.0
1.0
5.0
3.0
2.0
1.0
[torch.storage.TypedStorage(dtype=torch.float32, device=cpu) of size 6]
0
0
128
64
0
0
128
63
0
0
160
64
0
0
64
64
0
0
0
64
0
0
128
63
[torch.storage.UntypedStorage(device=cpu) of size 24]
array([[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]], dtype=float32)
(720, 1280, 3)