Issue
I have this tuple called train, containing 2 arrays, first (10000,10), second (1000):
(array([[0.0727882 , 0.82148589, 0.9932996 , ..., 0.9604997 , 0.48725072,
0.87095636],
[0.28299425, 0.94904277, 0.69887889, ..., 0.59392614, 0.96375439,
0.23708264],
[0.44746802, 0.46455956, 0.99537243, ..., 0.03077313, 0.60441346,
0.5284877 ],
...,
[0.74851845, 0.59469311, 0.20880812, ..., 0.82080042, 0.16033365,
0.94729764],
[0.56686195, 0.35784948, 0.15531381, ..., 0.95415527, 0.88907735,
0.39981913],
[0.61606041, 0.30158736, 0.65476444, ..., 0.0637397 , 0.76772078,
0.85285724]]), array([ 9.78050432, 21.84804394, 13.14748592, ..., 17.86811178,
14.94744237, 9.80791838]))
I've tried this to them stack them but there is a shape mismatch
seq = torch.as_tensor(train[0], dtype=None, device=None)
label = torch.as_tensor(train[1], dtype=None, device=None)
#seq.size() = torch.Size([10000,10])
#label.size() = torch.Size([10000])
My goal is to stack 10000 tensors of len(10) with the 10000 tensors label. Be able to treat a seq as single tensor like people do with images.
Where one instance would look like this like this:
[tensor(0.0727882 , 0.82148589, 0.9932996 , ..., 0.9604997 , 0.48725072,
0.87095636]), tensor(9.78050432)]
Thanks you,
Solution
Where/what is your error exactly?
Because, to get your desired output it looks like you could just run:
stack = [[seq[i],label[i]] for i in range(seq.shape[0])]
But, if you want a sequence of size [10000,11], then you need to expand the dims of the label tensor to be concatenatable (made that word up) along the second axis:
label = torch.unsqueeze(label,1)
stack = torch.cat([seq,label],1)
Answered By - jhso
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.