Suppose I execute the following code
JavaScript
x
4
1
W = tf.random.uniform(shape = (100,1), minval = 0, maxval = 1)
2
Z = tf.random.uniform(shape = (100,1), minval = 0, maxval = 1)
3
X = tf.concat([W,Z],1)
4
The shape of X[:,1]
would be [100,]
. That is, X[:,1].shape
would yield [100,]
. If I want to select the second column of X
and want the resulting array to have shape [100,1]
, what should I do? I looked at tf.slice
but I’m not sure if it’ helpful.
Advertisement
Answer
Maybe just use tf.newaxis
for your use case:
JavaScript
1
9
1
import tensorflow as tf
2
3
W = tf.random.uniform(shape = (100,1), minval = 0, maxval = 1)
4
Z = tf.random.uniform(shape = (100,1), minval = 0, maxval = 1)
5
6
X = tf.concat([W,Z],1)
7
print(X[:, 1, tf.newaxis].shape)
8
# (100, 1)
9