tensorflow python中的“使用序列设置数组元素”错误

时间:2019-05-22 20:34:39

标签: python numpy tensorflow deep-learning

我正在写一个带有错误消息的张量流代码:

  

设置具有序列的数组元素。

错误在第cluster_std[cluster_i] = cluster_std[cluster_i]+t_err行中。我想问题是t_err,我猜是张量流操作;我该如何解决这个问题?谢谢!

def loss_kmeans_reconst(cluster_ass, out):
    cluster_mean = tf.unsorted_segment_mean(out, np.arange(nb_realizations), nb_realizations)
    # if you do not know unsorted_segment_mean, you can think cluster_mean as a tensor which has same shape
    # as out
    cluster_std = np.zeros((nb_centroids))

    for i in range(0,nb_realizations):
        cluster_i = cluster_ass[i]
        t_err = tf.reduce_sum(tf.square(out[i,:]-cluster_mean[cluster_i,:]))     
        cluster_std[cluster_i] = cluster_std[cluster_i]+t_err


    return np.mean(cluster_std)

test_out = tf.ones([nb_realizations,121],tf.float64)
test_return = loss_kmeans_reconst(np.arange(nb_realizations), test_out)
print(test_return.shape)

0 个答案:

没有答案