title: Access the weight matrix in Tensorflow in order to make apply changes to it in Numpy
body: <p>I need a way to have access to the weight matrix in TensorFlow or Keras within each iteration, so that I can convert it into a format that I can use in Numpy to carry out certain operations on it, then send it back to TensorFlow.</p>
  
  <p>For example, I want to change my filter such that some of the neurons are specified by others neuron of the filter. They have to be obtained as solutions of linear systems with other neurons as its coefficients, not by the learning process. As I could not find a way to do this in TensorFlow or Keras, I have to use Numpy.</p>
  
  <p>I have found many questions with the same or similar titles, but none of them helped. I would appreciate any hints.</p>
  
  <p><strong>EDIT</strong>
  let me explain the problem more clearly 
  consider the following code</p>
  
  <pre><code>import tensorflow as tf
  import numpy as np
  
  x = tf.placeholder(tf.float32, (1, 5, 5, 1))
  y = tf.placeholder(tf.float32, (1))
  
  # create variable
  weights = {
      "my_filter": tf.Variable(tf.truncated_normal([3, 3, 1, 1]), name="my_filter"),
      "f_c": tf.Variable(tf.truncated_normal([25,1]), name="f_c") }
  
  
  conv = tf.nn.conv2d(x, weights["my_filter"], [1,1,1,1], padding='SAME')
  flatten= tf.reshape(conv,[1,25])
  logits= tf.matmul(flatten,weights["f_c"])
  
  
  cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits,labels= y))
  optmize = tf.train.AdamOptimizer()
  grads_and_vars = optmize.compute_gradients(cost)
  #In this part before applying gradient I have to apply some complicated mathematical operation
  train_op=optmize.apply_gradients(grads_and_vars)
  
  
  
  train_epochs=10
  input_x = np.arange(25).reshape([1,5,5,1])
  input_y = np.arange(1)
  
  with tf.Session() as sess:
  
      sess.run(tf.global_variables_initializer())
  
      for epoch in range(train_epochs):
  
          sess.run(train_op, feed_dict={x: input_x, y: input_y})
  </code></pre>
  
  <p>I have a 5*5 filter named my_filter and I want all its elements to be trained except for one of them, for exaple the (1,1) element, and I need the latter element to be determined by the rest of the elemnets. This has to be done in each iteration. This is exactly where my problem is. I know how to access the weight matrix after the training is finished, but I do not know how to do this within each iteration.</p>
  
  <p>In my code, I have first computed the gradients, then made the changes,  and then applied the gradients. But the problem is that the gradients are tuples of types, for exapmle tensor, which are not easy to work with in Numpy. I need some method to convert these data to more familiar Numpy types.</p>