# Why using negative integers (as dimensions?) in tensor shapes rather than natural numbers?

Consider the following paragraph from A.1 MULTI-MNIST AND CLEVR of A IMPLEMENTATION DETAILS from the research paper titled GENERATING MULTIPLE OBJECTS AT SPATIALLY DISTINCT LOCATIONS by Tobias Hinz et al.

In the global pathway of the generator we first obtain the layout encoding. For this we create a tensor of shape (10, 16, 16) (CLEVR: (13, 16, 16)) that contains the one-hot labels at the location of the bounding boxes and is zero everywhere else. We then apply three convolutional layers, each followed by batch normalization and a leaky ReLU activation. We reshape the output to shape (1, 64) and concatenate it with the noise tensor of shape (1, 100) (sampled from a random normal distribution) to form a tensor of shape (1, 164). This tensor is then fed into a dense layer, followed by batch normalization and a ReLU activation and the output is reshaped to (−1, 4, 4). We then apply two upsampling blocks to obtain a tensor of shape (−1, 16, 16).

The paragraph is saying that a tensor of shape (1, 164) is reshaped to (-1, 4, 4). What is the reason behind using negative number -1? Is it representing axis? Can't we represent it with $$a \times x \times y$$, where $$a, x, y$$ are natural number s and dimensions of the tensor?

$$\dfrac{164}{4 \times 4}$$ is not a natural number, so what is the shape of the reshaped tensor using only the natural numbers?

• This seems to be just a programming question, so I will close it, unless you clarify how this is not just a programming question.
– nbro
Sep 17 at 13:18
• @nbro my primary question is what -1 represents: dimension or axis. Sep 17 at 13:20
• In my view, this is still a programming question, because -1 may not exist in all libraries, and its meaning may depend on the specific library. The other linked question that I answered could also be considered a programming question for the same reason. I would avoid asking these questions here, if you don't want them to be closed. I will leave this open for now, but to me this seems to be off-topic.
– nbro
Sep 17 at 13:25
• @nbro But, authors started using them in their research papers. What would you say about this? i mean, what is your opinion on it? Sep 17 at 13:31
• The 164 tensor is not reshaped to (-1,4,4). It is fed to a dense layer and the output of the dense layer is reshaped to (-1,4,4) Sep 17 at 13:35

It definitely is. If you check the code (line 145) you'll see that in the forward definition of the Stage1 Generator they do:

class STAGE1_G(nn.Module):
def __init__(self):
...
def forward(self, text_embedding, noise):
c_code, mu, logvar = self.ca_net(text_embedding)
z_c_code = torch.cat((noise, c_code), 1)
h_code = self.fc(z_c_code)

h_code = h_code.view(-1, self.gf_dim, 4, 4)


Where self.gf_dim is a parameter defined in the configuration file of the gan (most likely number of feature maps, but check cause they didn't write documentation about the config settings)