In [1]:
import torch
import matplotlib.pyplot as plt
In [2]:
t_one = torch.tensor([1,2,3])
t_two = torch.tensor([1,2,3])
t_one + t_two
Out[2]:
tensor([2, 4, 6])
In [3]:
t_one * t_two
Out[3]:
tensor([1, 4, 9])
In [4]:
t_one *5
Out[4]:
tensor([ 5, 10, 15])
In [5]:
dot_product = torch.dot(t_one, t_two)
print(dot_product)
tensor(14)
In [6]:
torch.linspace(0,10) # default number: 100
Out[6]:
tensor([ 0.0000,  0.1010,  0.2020,  0.3030,  0.4040,  0.5051,  0.6061,  0.7071,
         0.8081,  0.9091,  1.0101,  1.1111,  1.2121,  1.3131,  1.4141,  1.5152,
         1.6162,  1.7172,  1.8182,  1.9192,  2.0202,  2.1212,  2.2222,  2.3232,
         2.4242,  2.5253,  2.6263,  2.7273,  2.8283,  2.9293,  3.0303,  3.1313,
         3.2323,  3.3333,  3.4343,  3.5354,  3.6364,  3.7374,  3.8384,  3.9394,
         4.0404,  4.1414,  4.2424,  4.3434,  4.4444,  4.5455,  4.6465,  4.7475,
         4.8485,  4.9495,  5.0505,  5.1515,  5.2525,  5.3535,  5.4545,  5.5556,
         5.6566,  5.7576,  5.8586,  5.9596,  6.0606,  6.1616,  6.2626,  6.3636,
         6.4646,  6.5657,  6.6667,  6.7677,  6.8687,  6.9697,  7.0707,  7.1717,
         7.2727,  7.3737,  7.4747,  7.5758,  7.6768,  7.7778,  7.8788,  7.9798,
         8.0808,  8.1818,  8.2828,  8.3838,  8.4848,  8.5859,  8.6869,  8.7879,
         8.8889,  8.9899,  9.0909,  9.1919,  9.2929,  9.3939,  9.4949,  9.5960,
         9.6970,  9.7980,  9.8990, 10.0000])
In [7]:
torch.linspace(0,10,5)
Out[7]:
tensor([ 0.0000,  2.5000,  5.0000,  7.5000, 10.0000])
In [8]:
x = torch.linspace(0,10,100)
y = torch.exp(x)
plt.plot(x.numpy(),y.numpy())
plt.show()
In [9]:
y = torch.sin(x)
plt.plot(x.numpy(),y.numpy())
plt.show()