Svtter
10/21/2017 - 2:48 PM

learning pytorch stage one.

learning pytorch stage one.

# coding: utf-8
import torch
import numpy as np
np_data = np.arange(6)
np_data
np_data = np.arange(6).reshape((2, 3))
np_data
torch_data = torch.from_numpy(np_data)
torch_data
print(np_data)
print(torch_data)
tensor2array = torch_data.numpy()
print(
    '\nnumpy array:', np_data,
    '\ntorch tensor: ', torch_data,
    '\ntensor to array', tensor2array,
)
data = [-1, -2, 1, 2]
tensor = torch.FloatTensor(data)
tensor
np.abs(data)
torch.abs(tensor)