Its very simple you just have to create a rotation matrix :
https://www.mathworks.com/matlabcentral/answers/339432-how-to-rotate-an-image-using-rotation-matrix 23
or you can check this post for suggested codes:

  
    
    
    Affine transformation matrix paramters conversion vision
  
  
    How are you comparing the results? 
It seems scipy.ndimage.affine_transform uses pixel values for the translation part, while F.affine_grid seems to want values in the range [-1, 1] (which you already provided). 
This code tries to rotate and translate a line: 
x = torch.eye(10).view(1, 1, 10, 10)
theta = torch.zeros(1, 2, 3)
angle = np.pi/2.
theta[:, :, :2] = torch.tensor([[np.cos(angle), -1.0*np.sin(angle)],
                                [np.sin(angle), np.cos(angle)]])
theta[:, :, 2] = 0.5
…