< Back

Env

import torch

common operations

x = torch.tensor([1.0, 2, 4, 8])
y = torch.tensor([2, 2, 2, 2])
x + y, x - y, x * y, x / y, x ** y
Output
(tensor([ 3.,  4.,  6., 10.]),
 tensor([-1.,  0.,  2.,  6.]),
 tensor([ 2.,  4.,  8., 16.]),
 tensor([0.5000, 1.0000, 2.0000, 4.0000]),
 tensor([ 1.,  4., 16., 64.]))

common operations

torch.exp(x)
what's this?

\( y_i = e^{x_i} \)
计算Tensor中每个元素 \( x_i \) 的以自然常数 e(约等于 2.71828)为底的指数
一种激活函数,是softmax、sigmoid等的组成

output
tensor([2.7183e+00, 7.3891e+00, 5.4598e+01, 2.9810e+03])