zip() Creates an One-time Iterator
zip() stacks two lists and creates an one-time iterator. This iterator could be used only once.
a = range(5)
b = range(5)
iter1 = zip(a,b)
print(list(iter1)) # working
print(list(iter1)) # empty-iterator
Output:
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)]
[]
If we want to reuse the result, we could list() the iterator.
a = range(5)
b = rang...
(PyTorch) Tensor (array) and List Slicing
In PyTorch and Numpy, slicing format differs from that of Python list.
tensor[:2] stands for the first and second samples.
tensor = torch.ones([5,32,32,1])
lists = list(range(0,5120))
print(tensor[:2].shape) # torch.Size([2, 32, 32, 1])
tensor[:2,1] stands for the second row of the first two samples.
print(tensor[:2, 1].shape) # torch.Size([...
18 post articles, 3 pages.