Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Numpy 在Tensorflow图中使用scipy.stats.entropy_Numpy_Tensorflow_Scipy_Tensor_Entropy - Fatal编程技术网

Numpy 在Tensorflow图中使用scipy.stats.entropy

Numpy 在Tensorflow图中使用scipy.stats.entropy,numpy,tensorflow,scipy,tensor,entropy,Numpy,Tensorflow,Scipy,Tensor,Entropy,我的目标是在下面的代码片段中计算两个概率密度函数p_distb和q_distb之间的距离。我试图利用Jensen-Shannon散度来实现这一点,因为它是对称且有界的,所以必要的熵函数是从scipy.stats导入的 尝试运行图表时,出现以下错误: 如果len(qk)!=len(主键): TypeError:未调整大小的对象的len() 显然,scipy.stats.entropy无法处理张量流张量,即使这些张量是向下兼容的,并且应该像numpy数组一样工作 有人能解决这个问题吗 非常感谢 fr

我的目标是在下面的代码片段中计算两个概率密度函数p_distb和q_distb之间的距离。我试图利用Jensen-Shannon散度来实现这一点,因为它是对称且有界的,所以必要的函数是从scipy.stats导入的

尝试运行图表时,出现以下错误:

如果len(qk)!=len(主键): TypeError:未调整大小的对象的len()

显然,scipy.stats.entropy无法处理张量流张量,即使这些张量是向下兼容的,并且应该像numpy数组一样工作

有人能解决这个问题吗

非常感谢

from scipy.stats import entropy
import tensorflow as tf
import numpy as np

graph = tf.Graph()
with graph.as_default():

i_dim = 8
j_dim = 8

input_dim = 201

weights = tf.Variable(tf.random_normal(shape=[i_dim*j_dim, input_dim]))

input_vector = tf.Variable(tf.random_normal(shape=[input_dim,1]))

min_codebook_dist = []

for index in range(i_dim*j_dim):

    p_distb = tf.div(weights[index,:],tf.reduce_sum(weights[index,:]))
    p_distb = tf.reshape(p_distb, shape=[input_dim,])

    q_distb = tf.div(input_vector,tf.reduce_sum(input_vector))
    q_distb = tf.reshape(input_vector, shape=[input_dim,])

    m_distb = tf.div(tf.add(p_distb,q_distb),2)

    dist_pq = np.sqrt((entropy(p_distb[:], m_distb[:]) + entropy(q_distb[:], m_distb[:])) / 2)

    min_codebook_dist.append(dist_pq)

sess = tf.InteractiveSession()
init_op = tf.initialize_all_variables()
sess.run(init_op)

TensorFlow张量与numpy数组不向下兼容。您可以尝试在tf.py_func中包装对scipy的呼叫以呼叫scipy。

谢谢您的帮助!!