简体   繁体   中英

TensorFlow: the best way to convert a scalar to a 1-dimensional tensor

I have to convert tensorflow scalars into 1-dimensional tensors with 1 element. I wonder what is the best way to do this?

You can use tf.reshape

For example:

import tensorflow as tf
x = tf.constant(2)
x_1d = tf.reshape(x, [1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM