December 2017
Beginner to intermediate
470 pages
12h 29m
English
In the previous section, we realized how large an impact can unnecessary overhead within iterations have on our implementation's performance. However, what if we could avoid iterating at all? Now that would be better, wouldn't it? Well, as we mentioned earlier, doing so is achievable with vectorization.
In this case, we will remove the while loop and replace it with a vectorized mean over the start and end positions, where end continues to be defined as it has been so far, and start is defined as the end position minus period we receive as a parameter, plus one. This ensures that we get the exact number of prices we need, and we can create an interval with start:end that will take the specific subset we ...