Build Better Generative Adversarial Networks (GANs): week2 Assignment, covariance

I have been for a while on the covariance_matrix_from_examples.
my issue seems to be with the assert evaluation section.
here is what I did. I am having a error flag but I am not able to figure out why it is not working.

examples_reshape = examples.reshape(2, examples.shape[0]*examples.shape[1], examples.shape[-1]//2)
return np.cov(examples_reshape[0], examples_reshape[1], rowvar= False)

I think you’re making this way more complicated than it needs to be. Note that you’ve given 3 distinct arguments to reshape. What’s up with the 2 as the first dimension on the reshape? And the divide by 2 thing? You’re given a 3D array with “features” as the last dimension. All you need to do is preserve the “features” dimension and unroll the first two dimensions so that you end up with a 2D array with features as the second dimension. The easiest way is to use the -1 trick on reshape to say “Use whatever is left here” for the first dimension.

1 Like

Got you! I was using a hammer to kill a fly. everything is ok now. Thank you!

That’s a good analogy. And you missed the fly and hit your thumb instead. :laughing:

Glad to hear you got it sorted out. :nerd_face: