我希望下面的代碼產生相應的張量>>> A = tf.range(3)>>> B = tf.tile(tf.expand_dims(A), [4,1])>>> print(tf.Session().run(B))[[0,1,2], [0,1,2], [0,1,2], [0,1,2]]但是,這會導致ValueError. 重現(xiàn)問題的簡單方法如下>>> import tensorflow as tf>>> x = tf.constant([0,1,2])>>> y = tf.expand_dims(x)ValueError: Tried to convert 'dim' to a tensor and failed. Error: None values not supported.使用expand_dims和避免此錯誤的正確方法是什么?
使用 expand_dims 時“試圖將 'dim' 轉換為張量并失敗”
函數(shù)式編程
2021-09-11 15:51:04