Open galv opened 8 years ago
There is a helper function for that in nn
if you want.
It can be found in nn.utils.addSingletonDimension
.
Given that there is a nn
function called Unsqueeze
that does exactly what you want (and no torch counterpart), I think it's reasonable to include a unsqueeze
function in torch following the implementation of addSingletonDimension
.
Amazing, thanks for letting me know about this.
I agree, a torch.unsqueeze()
would be handy.
For anybody else coming accross this, the unsqueeze function now exists: http://pytorch.org/docs/master/torch.html#torch.unsqueeze EDIT: Well, it exists in pytorch, anyway. :)
~Yes, we also can use the numpy notation for adding new dimensions, like tensor[None, :, None]
.~ Oups, this is torch7 repo, no pytorch...
I'm annoyed that to add a singleton dimension to a tensor, I have to use two lines of code. Like this:
I would really like a one-liner for this. Does anyone have any suggestions?
If not, how open are the maintainers to my adding a new function to the library to do this?