Comprehension

Comprehensions works similar to for loop except that it can be expressed into a single line. For example, below will iterate the process of summing three variables that takes different integer in a range of 1 and 3. This will produce 27 different cases each of which will be stored in 3x3x3 array. [ i + j + k for i=1:3, j=1:3, k=1:3 ] Output: 3×3×3 Array{Int64, 3}: [:, :, 1] = 3 4 5 4 5 6 5 6 7 [:, :, 2] = 4 5 6 5 6 7 6 7 8 [:, :, 3] = 5 6 7 6 7 8 7 8 9

April 4, 2023 · 1 min · 107 words · Me