
Link to the classroom item: [Coursera  Online Courses & Credentials From Top Educators. Join for Free  Coursera](https://Classroom item)

Description
I don’t understand why the need to create a mean_matrix using np.repeat and np.reshape, the same size as the original Y and not just compute the mean_vector and subtract it from Y
If we computed X = Y  mean_vector directly, the subtraction would broadcast rowwise and give the same result ?
1 Like
Yes, you’re right: I don’t know why they suggest doing things in that complicated way. I also did it by taking advantage of “broadcasting” and it works fine and passes the grader. Much simpler code to write. Simpler is better!
It’s been a while since I watched the lectures here, but maybe they just didn’t want to explain how broadcasting works. I was a math major back in the day, so I remember when I first saw broadcasting maybe 10 years ago, I thought it was kind of a shocking violation of the underlying pure math concepts. And it could have nasty unintended consequences if the dimension mismatch was just a bug by a careless user, but once you get used to it, it sure is convenient.
1 Like
Thank you for your answer.