0
我遇到以下代码段obs_pattern
,obs_seq
和obs_seq_s
不会产生预期行为的问题。我尝试过使用TensorFlow 1.2.1。我怀疑有什么不对。交互式会话eval和tf.random_uniform不会产生预期的输出
import tensorflow as tf
sess = tf.InteractiveSession()
seq_length = 5
num_bits = 4
obs_pattern_shape = [num_bits, seq_length]
obs_pattern = tf.cast(
tf.random_uniform(obs_pattern_shape, minval=0, maxval=2, seed=1234, dtype=tf.int32),
tf.float32)
print(obs_pattern.eval())
seq_length_zeros = tf.zeros([1, seq_length])
obs_seq = tf.concat([obs_pattern, seq_length_zeros], axis=0)
print(obs_seq.eval())
add_vec = tf.one_hot([num_bits], (num_bits + 1), on_value = 1.0, off_value=0.0, axis=0)
obs_seq_s = tf.concat([obs_seq, add_vec], axis=1)
print(obs_seq_s.eval())
sess.close()
obs_pattern
[[ 1. 1. 1. 0. 0.]
[ 0. 0. 0. 1. 0.]
[ 0. 1. 1. 0. 0.]
[ 0. 1. 0. 0. 0.]]
obs_seq
[[ 1. 1. 0. 1. 1.]
[ 0. 1. 1. 0. 1.]
[ 1. 1. 1. 0. 0.]
[ 1. 1. 0. 1. 0.]
[ 0. 0. 0. 0. 0.]]
obs_seq_s
[[ 1. 0. 0. 0. 0. 0.]
[ 0. 0. 1. 0. 0. 0.]
[ 0. 1. 0. 0. 0. 0.]
[ 0. 1. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 1.]]
编辑:基于吨 他评论下面我改变obs_pattern和它的行为,因为我还以为
import numpy as np
arr = np.random.randint(2, size=(num_bits, seq_length))
obs_pattern = tf.convert_to_tensor(arr, dtype=tf.float32)
甜美!感谢那 – flyingmadden