用一个自定义的数组初始化tensorflow variable

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/guotong1988/article/details/82951096
import tensorflow as tf
tf.enable_eager_execution()

value = [0, 1, 2, 3, 4, 5, 6, 7]
init = tf.constant_initializer(value)
x = tf.get_variable('x', shape=[8], initializer=init)
print(x)

打印结果:

<tf.Variable ‘x:0’ shape=(8,) dtype=float32, numpy=array([0., 1., 2., 3., 4., 5., 6., 7.], dtype=float32)>

猜你喜欢

转载自blog.csdn.net/guotong1988/article/details/82951096