About converting PIL Image to PyTorch Tensor

I use PIL open an image:

pic = Image.open(...).convert('RGB')

Then I want to convert it to tensor, I have read torchvision.transforms.functional, the function to_tensor use the following way:

img = torch.ByteTensor(torch.ByteStorage.from_buffer(pic.tobytes()))
img = img.view(pic.size[1], pic.size[0], len(pic.getbands()))

Why not use the following method directly:

img = torch.from_numpy(np.array(pic))

I want to know what is the difference, is it because of the difference in efficiency?

Did not know about the first line, but the second line change [W,H,C] => [C,W,H]