episode 9 (vectorizing): compare with for loop output? #523
Hi Carpentries folks,
The listed key point in episode 9 about vectorizing is to
which is great! However, in the episode, there are no side-by-side examples of accomplishing the same task using both a vectorized call and a for loop. The first piece of explanatory text in the lesson plan explicitly compares vectorizing with for looping:
This could couple really well with a worked example showing a multi-line for loop that loops over the indices of a vector, and contrasting it with a single-line vectorized call that has equivalent output. That might serve to make very concrete that vectorized functions are often less verbose than equivalent for loops. Learners coding along would likely find that typing the vectorized call is much faster and less typo-prone than typing out the for loop, thus hitting the point home.
Since this episode comes after the control flow episode, presumably learners will have seen a for loop before, so including a for loop in the worked code hopefully wouldn't take too much time for explanation.
I know adding worked code examples to episodes is tough since they're already so info-packed, but this might be able to be substituted for the chunk explaining
happy to discuss and maybe to try suggesting edits in a PR, but figured opening an issue was a good place to start.
(PS: I am doing this as part of instructor training checkout)
Thanks for this suggestion, @monicathieu . I think it raises a great point about having side-by-side comparisons accomplishing the same task via loop and via the built-in vectorization. Perhaps Challenge 1 could be revised to ask for two solutions: a for loop and a vectored approach (the former might seem a bit artificial at this point of the lesson, but would help reinforce loop syntax). But other means of accomplishing this are worth investigating.
I think a side-by-side comparison is the best way to let learners see that vectorized code is more concise, easy to read, and less error prone as claimed in the lesson.
As noted by @monicathieu, since the for-loop syntax was already covered in the control flow episode, I don't even think that we are actually adding a new concept, just making the claims about vectorized code more concrete for learners.
My suggestion would be to add something like the following right before Challenge 1.
Here is how we would achieve the same result of adding two vectors together using a for loop:
Thanks, @fjuniorr . One minor suggestion would be to skip
referenced this issue
Jul 14, 2019
@jcoliver I can see how identical can be unnecessary in this case. But since the