这导致以下错误。 “ ValueError:仅变量支持切片分配”我认为问题是我无法进行投射
variable_test = tf.reshape(corel_matrix[1], [])
成标量。如果variable_test是标量,则可以在以下代码中将其分配到tf.variable中:matrix_of_correlations_variable。任何帮助和指导将不胜感激。
import tensorflow as tf
import numpy as np
from tensorflow.contrib.metrics import streaming_pearson_correlation
NUM_OF_FEATURES = 10
NUM_OF_DATA = 20
R = tf.Variable(tf.random_normal((NUM_OF_DATA,NUM_OF_FEATURES)), name="random_weights")
matrix_of_correlations_variable = tf.get_variable("matrix_of_correlations_variable", shape=[NUM_OF_FEATURES, NUM_OF_FEATURES])
for i in range(NUM_OF_FEATURES):
for j in range(i+1, NUM_OF_FEATURES):
corel_matrix = streaming_pearson_correlation(R[:,i],R[:,j])
corel_matrix2 = corel_matrix[1]
variable_test = tf.reshape(corel_matrix[1], [])
print(variable_test)
matrix_of_correlations_variable = matrix_of_correlations_variable[i,j].assign(variable_test)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
print(sess.run(matrix_of_correlations_variable))