Follow the the following instructions to make the program in Python for XOR/OR/A
ID: 3593215 • Letter: F
Question
Follow the the following instructions to make the program in Python for XOR/OR/AND Gate.
You should finish this program. For example for the OR gate if the input is (0,0) you should get a 0. If input is (0,1) you should get a 1 etc. Same for the AND gate. You should try to do this for the XOR but it wont work. You should get a number output using the weights W and bias that the scipy minimize function returns (res.x[0]=w0,res.x[1]=w1,res.x[2]=bias). Calculate the outputs!!! (note the plural) as np.dot(X,W)+bias (where W[0,0]=res.x[0],W[1,0] = res.x[1] and bias =res.x[2]). You could now use a loop and if to find out which of 0 or 1 your answers are closest too. You can then decide that indeed you have learned the gate. I would like you to do this in numpy without using loops but with matrix manipulations.
Explanation / Answer
def funAnd():
if condition1 and condition2:
return True
#######
0 | 0 -> 0
0 | 1 -> 0
1 | 0 -> 0
1 | 1 -> 1
def funOr():
if condition1 or condition2:
return True
#######
0 | 0 -> 0
0 | 1 -> 1
1 | 0 -> 1
1 | 1 -> 1