Permutate MNIST -- Help Needed?

Need confirmation for the method I am following to implement the permutated MNIST

print("Applying permutation to MNIST pixels")
rng_permute = np.random.RandomState(92916)
idx_permute = rng_permute.permutation(784)
transform = torchvision.transforms.Compose([torchvision.transforms.ToTensor(),
              torchvision.transforms.Lambda(lambda x: x.view(-1,1)[idx_permute])])

train_loader = torch.utils.data.DataLoader(datasets.MNIST('data', train=True, download=True,
                   transform=transform),batch_size=32, shuffle=True)

Is what I am doing the correct way?

When I a trying to view the images I am getting the error:

import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
# functions to show an image


def imshow(img):
    img = img / 2 + 0.5     # unnormalize
    npimg = img.numpy()
    plt.imshow(np.transpose(npimg, (1, 2, 0))) #if i remove (1,2,0) it showing single vector.


# get some random training images
dataiter = iter(train_loader)
images, labels = dataiter.next()

# show images
imshow(torchvision.utils.make_grid(images))

Overall my main Aim is to prepare the Permutated MNIST dataset…

it should be:

idx_permute = torch.from_numpy(rng_permute.permutation(784), dtype=torch.int64)
transform = torchvision.transforms.Compose([torchvision.transforms.ToTensor(),
              torchvision.transforms.Lambda(lambda x: x.view(-1)[idx_permute].view(1, 28, 28) )])

Hey Thank you … I did finished it .Taking reference from the EWC implementation of Pytorch