0
    import tensorflow as tf
    import numpy as np

    layer1_weight = tf.Variable(tf.zeros([2 , 3]))
    layer1_bias = tf.Variable(tf.zeros([3 , 1]))
    layer2_weight = tf.Variable(tf.zeros([3, 1]))
    layer2_bias = tf.Variable(tf.constant([[0.]]))
    input = tf.placeholder(tf.float32 , [2 , 1] )
    result = tf.placeholder(tf.float32 ,[1 , 1] )

    data_input = [np.float32([[0.],[0.]]) , np.float32([[0.],[1.]]) , 
    np.float32([[1.],[0.]]) , np.float32([[1.],[1.]])]
    data_output = [np.float32([[0.]]) , np.float32([[1.]]) , 
    np.float32([[1.]]) , np.float32([[0.]])]
    layer1_output = tf.add(tf.matmul(tf.transpose(layer1_weight) , input) , 
    layer1_bias )
    layer2_output = tf.add(tf.matmul(tf.transpose(layer2_weight) , 
    layer1_output) , layer2_bias)
    print (data_input[0])
    loss = tf.square(tf.subtract(result , layer2_output))
    optimizer = tf.train.GradientDescentOptimizer(0.0001)
    train_step = optimizer.minimize(loss)


    sess = tf.Session()
    init = tf.global_variables_initializer()
    sess.run(init)

    for i in range(30) :
        j = int(i % 4)
        result = data_output[j]
        sess.run(train_step , feed_dict= {input : data_input[j] , result : 
        data_output[j]})
        print(str(layer2_output))

The code is returning Error

TypeError: unhashable type: 'numpy.ndarray'

Here I am trying to implement XOR gate with neural network but can't find error.

1 Answer 1

2

First you define result to be a placeholder, but later redefine it as result = data_output[j]. This is when it gets wrong, because you can no longer feed the value to feed_dict.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.