# UNQ_C4 Dimension mismatch error

I am getting an error

RuntimeError                              Traceback (most recent call last)
Input In [14], in <cell line: 16>()
     31 fake_noise = get_noise(cur_batch_size, z_dim, device=device)
     33 # Now you can get the images from the generator
     34 # Steps: 1) Combine the noise vectors and the one-hot labels for the generator
     35 #        2) Generate the conditioned fake images
     36 
     37 #### START CODE HERE ####
---> 38 noise_and_labels = combine_vectors(fake_noise,image_one_hot_labels)
     39 fake = gen(noise_and_labels)
     40 #### END CODE HERE ####
     41 
     42 # Make sure that enough images were generated

Input In [7], in combine_vectors(x, y)
      4 '''
      5 Function for combining two vectors with shapes (n_samples, ?) and (n_samples, ?).
      6 Parameters:
   (...)
     12     with the shape (n_samples, n_classes), but you shouldn't assume this in your code.
     13 '''
     14 # Note: Make sure this function outputs a float no matter what inputs it receives
     15 #### START CODE HERE ####
---> 16 combined = torch.cat((x.float(),y.float()),1)
     17 #### END CODE HERE ####
     18 return combined

RuntimeError: Tensors must have same number of dimensions: got 2 and 4

Although all the previous code blocks have passed successfully. My combine_vectors function uses

combine=torch.cat((x.float(),y.float()),1)
return combine

What I understand from the error is that those 2 variables have got different dimensions and cant be combined together. Check their origin and why is the case so by tracing them back where they originate from…

I found the answer and it was a little typo in here.

 combine_vectors(fake_noise,image_one_hot_labels)

should actually be

 combine_vectors(fake_noise,one_hot_labels)
1 Like