<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <img src="../Pierian-Data-Logo.PNG">
<br>
<strong><center>Copyright 2019. Created by Jose Marcial Portilla.</center></strong>
PyTorch Basics Exercises - SOLUTIONS
For these exercises we'll create a tensor and perform several operations on it.
<div class="alert alert-danger" style="margin
Step1:  2. Set the random seed for NumPy and PyTorch both to "42"
This allows us to share the same "random" results.
Step2:  3. Create a NumPy array called "arr" that contains 6 random integers between 0 (inclusive) and 5 (exclusive)
Step3:  4. Create a tensor "x" from the array above
Step4:  5. Change the dtype of x from 'int32' to 'int64'
Note
Step5:  6. Reshape x into a 3x2 tensor
There are several ways to do this.
Step6:  7. Return the right-hand column of tensor x
Step7:  8. Without changing x, return a tensor of square values of x
There are several ways to do this.
Step8:  9. Create a tensor "y" with the same number of elements as x, that can be matrix-multiplied with x
Use PyTorch directly (not NumPy) to create a tensor of random integers between 0 (inclusive) and 5 (exclusive).<br>
Think about what shape it should have to permit matrix multiplication.
Step9:  10. Find the matrix product of x and y
<ASSISTANT_TASK:>
Python Code:
# CODE HERE
import torch
import numpy as np
Explanation: <img src="../Pierian-Data-Logo.PNG">
<br>
<strong><center>Copyright 2019. Created by Jose Marcial Portilla.</center></strong>
PyTorch Basics Exercises - SOLUTIONS
For these exercises we'll create a tensor and perform several operations on it.
<div class="alert alert-danger" style="margin: 10px"><strong>IMPORTANT NOTE!</strong> Make sure you don't run the cells directly above the example output shown, <br>otherwise you will end up writing over the example output!</div>
1. Perform standard imports
Import torch and NumPy
End of explanation
# CODE HERE
np.random.seed(42)
torch.manual_seed(42);  # the semicolon suppresses the jupyter output line
Explanation: 2. Set the random seed for NumPy and PyTorch both to "42"
This allows us to share the same "random" results.
End of explanation
# CODE HERE
# DON'T WRITE HERE
arr = np.random.randint(0,5,6)
print(arr)
Explanation: 3. Create a NumPy array called "arr" that contains 6 random integers between 0 (inclusive) and 5 (exclusive)
End of explanation
# CODE HERE
# DON'T WRITE HERE
x = torch.from_numpy(arr)
print(x)
Explanation: 4. Create a tensor "x" from the array above
End of explanation
# CODE HERE
# DON'T WRITE HERE
x = x.type(torch.int64)
# x = x.type(torch.LongTensor)
print(x.type())
Explanation: 5. Change the dtype of x from 'int32' to 'int64'
Note: 'int64' is also called 'LongTensor'
End of explanation
# CODE HERE
# DON'T WRITE HERE
x = x.view(3,2)
# x = x.reshape(3,2)
# x.resize_(3,2)
print(x)
Explanation: 6. Reshape x into a 3x2 tensor
There are several ways to do this.
End of explanation
# CODE HERE
# DON'T WRITE HERE
print(x[:,1:])
# print(x[:,1])
Explanation: 7. Return the right-hand column of tensor x
End of explanation
# CODE HERE
# DON'T WRITE HERE
print(x*x)
# print(x**2)
# print(x.mul(x))
# print(x.pow(2))
# print(torch.mul(x,x))
Explanation: 8. Without changing x, return a tensor of square values of x
There are several ways to do this.
End of explanation
# CODE HERE
# DON'T WRITE HERE
y = torch.randint(0,5,(2,3))
print(y)
Explanation: 9. Create a tensor "y" with the same number of elements as x, that can be matrix-multiplied with x
Use PyTorch directly (not NumPy) to create a tensor of random integers between 0 (inclusive) and 5 (exclusive).<br>
Think about what shape it should have to permit matrix multiplication.
End of explanation
# CODE HERE
# DON'T WRITE HERE
print(x.mm(y))
Explanation: 10. Find the matrix product of x and y
End of explanation
<END_TASK>