Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
import torch
import numpy as np
#Input (temp,rainfall,humidity)
inputs=np.array([
[73,67,43],
[91,88,64],
[87,134,58],
[102,43,37],
[69,96,70]], dtype='float32')
inputs
array([[ 73., 67., 43.],
[ 91., 88., 64.],
[ 87., 134., 58.],
[102., 43., 37.],
[ 69., 96., 70.]], dtype=float32)
#Taregt (apples,oranges)
targets=np.array([
[56,70],
[81,101],
[119,133],
[22,37],
[103,119]],dtype='float32')
targets
array([[ 56., 70.],
[ 81., 101.],
[119., 133.],
[ 22., 37.],
[103., 119.]], dtype=float32)
#convert inputs and targets into tensors
inputs=torch.from_numpy(inputs)
targets=torch.from_numpy(targets)
print(inputs)
print(targets)
tensor([[ 73., 67., 43.],
[ 91., 88., 64.],
[ 87., 134., 58.],
[102., 43., 37.],
[ 69., 96., 70.]])
tensor([[ 56., 70.],
[ 81., 101.],
[119., 133.],
[ 22., 37.],
[103., 119.]])
#Weight and Biases
w=torch.randn(2,3,requires_grad=True)
b=torch.randn(2,requires_grad=True)
print(w)
print(b)
tensor([[-0.1534, -0.6423, 2.4070],
[ 1.2565, -0.5321, -0.1870]], requires_grad=True)
tensor([-0.8002, 1.3235], requires_grad=True)