简体   繁体   中英

How to change tensor shape in python?

Suppose I have, in Tensorflow, a tensor of shape [3,4,4] , which is not known explicitly. How can I change its shape to [3,4,4,1] ?
I tried to use reshape function but because I do not explicitly know the tensor shape, it cannot be used directly.

Given t of shape [3,4,4] , it can be reshape to [3,4,4, 1]

tf.reshape(t, [3,4,4, 1]) # by explicitly specifying the shape
tf.expandims(t, 3) # implicitly we expand the dimension 3 with size 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