title: How can I update tensor (weight value) trying to use two separate network?
body: <p>I've been trying to make AI for blackjack using RL. Now I'm trying to make two separate networks which is one way of DQN. I've searched the web and found some way and tried to use it but failed.</p>
  
  <p>This error has occurred:</p>
  
  <blockquote>
    <p>TypeError: Using a <code>tf.Tensor</code> as a Python <code>bool</code> is not allowed. Use <code>if t is not None:</code> instead of <code>if t:</code> to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>import gym
  import tensorflow as tf
  import matplotlib.pyplot as plt
  import numpy as np
  
  def one_hot(x):
      s=np.identity(600)
      b = s[x[0] * 20 + x[1] * 2 + x[2]]
      return b.reshape(1, 600)
  
  def boolstr_to_floatstr(v): 
  if v == True:
      return 1
  elif v == False:
      return 0
  
  env=gym.make('Blackjack-v0')
  learning_rate=0.5
  
  
  state_number=600
  action_number=2
  #######################################3
  X=tf.placeholder(tf.float32, shape=[1,state_number], name='input_data')
  W1=tf.Variable(tf.random_uniform([state_number,128],0,0.01))#network for update
  layer1=tf.nn.tanh(tf.matmul(X,W1))
  
  
  W2=tf.Variable(tf.random_uniform([128,256],0,0.01))
  layer2=tf.nn.tanh(tf.matmul(layer1,W2))
  
  W3=tf.Variable(tf.random_uniform([256,action_number],0,0.01))
  Qpred=tf.matmul(layer2,W3) # Qprediction
  #####################################################################3
  X1=tf.placeholder(shape=[1,state_number],dtype=tf.float32)
  W4=tf.Variable(tf.random_uniform([state_number,128],0,0.01))#network for target
  layer3=tf.nn.tanh(tf.matmul(X1,W4))
  
  
  W5=tf.Variable(tf.random_uniform([128,256],0,0.01))
  layer4=tf.nn.tanh(tf.matmul(layer3,W5))
  
  W6=tf.Variable(tf.random_uniform([256,action_number],0,0.01))
  target=tf.matmul(layer4,W6) # target
  #################################################################
  
  update1=W4.assign(W1)
  update2=W5.assign(W2)
  update3=W6.assign(W3)
  
  Y=tf.placeholder(shape=[1,action_number],dtype=tf.float32)
  
  loss=tf.reduce_sum(tf.square(Y-Qpred))#cost(W)=(Ws-y)^2
  train=tf.train.GradientDescentOptimizer(learning_rate=learning_rate).minimize(loss)
  
  
  
  
  
  num_episodes=1000 
  dis=0.99 #discount factor
  rList=[] #record the reward
  
  init=tf.global_variables_initializer()
  with tf.Session() as sess:
      sess.run(init)
      for i in range(num_episodes): #episode 만번
          s = env.reset()
          rALL = 0
          done = False
          e=1./((i/100)+1) #exploit or explore용 상수
          total_loss=[]
          while not done:  
  
              s = np.asarray(s)
              s[2] = boolstr_to_floatstr(s[2])
              #print(np.shape(one_hot(s)))
              #print(one_hot(s))
              Qs=sess.run(Qpred,feed_dict={X:one_hot(s).astype(np.float32)})
  
  
              if np.random.rand(1)&lt;e:   #새로운 도전시도
                   a=env.action_space.sample()
  
              else:
                   a=np.argmax(Qs) #그냥 내가아는한 최댓값의 액션 선택
  
  
  
              s1,reward,done,_=env.step(a)  #
              s1=np.asarray(s1)
              s1[2]=boolstr_to_floatstr(s1[2])
  
              if done:
                  Qs[0,a]=reward
  
              else:
                  Qs1=sess.run(target,feed_dict={X1:one_hot(s1)})
  
                  Qs[0,a]=reward+dis*np.max(Qs1) #optimal Q
  
              sess.run(train,feed_dict={X:one_hot(s),Y:Qs})
              if i%10==0: ##target 을 Qpredion으로 업데이트해줌
                  sess.run(update1,update2,update3)
  
          if reward==1:
              rALL += reward
          else:
              rALL+=0
          s=s1
  
          rList.append(rALL)
  
  
  
  print('success rate: '+ str(sum(rList)/num_episodes))
  print("Final Q-table values")
  </code></pre>
  
  <p>I need to print success rate finally. before DQN its 38%ish. If there is something wrong in my code considering its DQN algorithm, tell me please.</p>