It's better to have summaries if the code is relatively self-explanatory, and better to have comments in-line if it is unlikely to be possible to remember all the details by the time you hit the end. (Though in academic publishing, usually the code is just code and all explanations are outside.)
And if the comments say nothing that the code doesn't already say, it's better to leave them out! Giving the user twice as much to read while saying the same thing is not helpful.
(In your example, all the comments are of that sort.)