Ah, I see. Yeah, at least I'm not aware of how to do that with a
comprehension. You can unroll what a comprehension does and do it like:

z = zeros(3,2)
for i = 1:3
    z[i,:] = f()
end


It seems like it would be convenient to support syntax like:

[f()... for i = 1:3]

but you might need a way to specify the dimensions of the resulting matrix
as well.


On Wed, Aug 13, 2014 at 9:40 PM, Brendan O'Connor <breno...@cs.umass.edu>
wrote:

> But that calls `f()` on every loop of your comprehension, so it's probably
>> best to do something like:
>>
>> g = f()
>>
>> In  [13]: [g[i] for i=1:2, j=1:3]
>>
>> Out [13]: 2x3 Array{Any,2}:
>>  3.0  3.0  3.0
>>  5.0  5.0  5.0
>>
>
> Ah ... I should have said, actually, I don't want a constant value.  I
> wanted f() called 3 times, and its output arranged into a 3x2 matrix.
>
> [f()[i] for i=1:2, j=1:3]  is clever, but it calls f() 6 times.
>
> Brendan
>

Reply via email to