Search code examples
pythonnumpyvectorresizetorch

Resizing a vector by interpolation


I want to resize a vector by interpolating.

Torch happen to have a function to do that, but it does not work for 1D vectors !! Interpolate

 In [25]: torch.nn.functional.interpolate(torch.randn(5),10)


 NotImplementedError: Input Error: Only 3D, 4D and 5D input Tensors supported (got 1D) for the modes: nearest | linear | bilinear | bicubic | trilinear | area | nearest-exact (got nearest)

Any idea how to do that ?


Solution

  • this seem to work ... thanks @markoj

    In [70]: z=torch.randn(5)[None,None,:]
    
    In [71]: z
    Out[71]: tensor([[[ 0.90,  0.83, -1.57, -2.07,  0.99]]])
    
    In [72]: torch.nn.functional.interpolate(z,10)
    Out[72]: tensor([[[ 0.90,  0.90,  0.83,  0.83, -1.57, -1.57, -2.07, -2.07,  0.99,  0.99]]])