3
votes

i just have a brief question about the tensorflow reshape function. In tensorflow, you can initialize the shape of tensor placeholders with shape = (None, shape1, shape2, .. ). Now i looked at the reshape function and there they used -1 for the new reshape,

e.g. new_tensor = tf.reshape(old_tensor, shape = (-1 , shape1, shape2, .. ) )

Is -1 equivalent to None ? And if not, what's the difference between these two?

1

1 Answers

4
votes

No they are not equivalent.

When you use None for placeholder it means the dimension will be defined at run time (usually the batch size).

Whereas -1 in reshape means if (total size of data is s_0xs_1xs_2...) -1 will automatically infer s_0 and this I think is same as numpy's behaviour. You can't use None in reshape.