Good catch Kevin. Broadcasting works. Cheers

julia> function f1(n)
          A = rand(n,n,3) 
          S = rand(n,n)
          A ./ S 
       end
f1 (generic function with 1 method)

julia> function f2(n)
           A = rand(n,n,3); 
           S = rand(n,n); 
           for k = 1:size(A,3) 
               A[:,:,k] = A[:,:,k] ./ S; 
           end 
           return A 
       end
f2 (generic function with 1 method)

julia> begin
           srand(1)
           x = f1(10)
           srand(1)
           y = f2(10)
           x == y
       end
true

On Wednesday, August 27, 2014 9:57:40 AM UTC-7, Kevin Squire wrote:

Good thought, Ethan!  In fact, if you do it that way, broadcasting should 
> work--just divide by S.  (I'm not at a computer, so please test.) 
>
> Cheers,
>    Kevin
>
> On Wednesday, August 27, 2014, Ethan Anderes <ethana...@gmail.com 
> <javascript:>> wrote:
>
>> You could also re-arrange the indices and move the for loop to the last 
>> index
>>
>> function f(n)
>>     A = rand(n, n, 3) 
>>     S = rand(n, n) 
>>     for k = 1:size(A, 3) 
>>         A[:,:,k] = A[:,:,k] ./ S 
>>     end 
>>     return A 
>> end
>>
>> This works since A[:,:,k] is a 2-d array but A[k,:,:] is a 3-d array.
>> ​
>>
>  ​

Reply via email to