0

I have a tensor like this

indexes_batch  
[[28, 633, 1076, 332, 270, 123, 28, 6, 2],
 [47, 171, 120, 12, 261, 58, 1103, 6, 2],
 [1473, 3646, 7, 260, 4, 4, 4, 2],
 [531, 42, 55, 127, 654, 4, 2],
 [639, 6, 2]] 

when I use list(itertools.zip_longest(*indexes_batch, fillvalue=0)) I get
[(28, 47, 1473, 531, 639), (633, 171, 3646, 42, 6), (1076, 120, 7, 55, 2), (332, 12, 260, 127, 0), (270, 261, 4, 654, 0), (123, 58, 4, 4, 0), (28, 1103, 4, 2, 0), (6, 6, 2, 0, 0), (2, 2, 0, 0, 0)]

and use list(itertools.zip_longest(indexes_batch, fillvalue=0)),I get

[([28, 633, 1076, 332, 270, 123, 28, 6, 2],),
 ([47, 171, 120, 12, 261, 58, 1103, 6, 2],),
 ([1473, 3646, 7, 260, 4, 4, 4, 2],),
 ([531, 42, 55, 127, 654, 4, 2],),
 ([639, 6, 2],)]   

so waht I confused about is what is the function of * ,and why can * result a Transposed matrix

X.tang
  • 21
  • 3
  • because by unpacking you are matching every sublist indexes together, if not using `*` it it just packing the sublists into a tuple because there is not other elements to match in the same index. – Netwave Apr 17 '19 at 09:45
  • 1
    See https://stackoverflow.com/questions/19339/transpose-unzip-function-inverse-of-zip for an explanation. – Jussi Nurminen Apr 17 '19 at 09:45

0 Answers0