Code to reproduce output:
import torch
import numpy as np
import matplotlib.pyplot as plt
import imageio

angle = 90
affine_matrix = np.array(
        (
            (np.cos(np.deg2rad(angle)), -np.sin(np.deg2rad(angle)), 0),
            (np.sin(np.deg2rad(angle)),  np.cos(np.deg2rad(angle)), 0),
            (0, 0, 1)), dtype=np.double
    )
rotate_pyorch_2d = torch.from_numpy(affine_matrix[:2, :3]).unsqueeze(0)
grid_2d = torch.nn.functional.affine_grid(rotate_pyorch_2d, img_2d_tensor.shape)
pytorch_resampled_2d = torch.nn.functional.grid_sample(img_2d_tensor, grid_2d, mode="nearest", padding_mode="zeros")
plt.imshow(pytorch_resampled_2d.squeeze().permute(1,2,0).numpy().astype(np.uint8))