Does linear indexing not work with "a" directly?

On Saturday, October 11, 2014, Stephan Buchert <[email protected]>
wrote:

> Yes, this is nice.
>
> I had expected, that
>
> b=reshape(a, ...)
>
> is equivalent to
>
> b=reshape(copy(a), ...)
>
> i.e. changing the values in b wouldn't be visible in a. And that a
> function creating only a new binding to the same values would be reshape!
> Compare also with resize!
>
> But anyway, great. Now I can get Matlab-type "linear indices":
>
> julia> vector(a)=reshape(a, prod(size(a)))
> vector (generic function with 1 method)
>
> julia> a=[1 2; 3 4; 5 6]
> 3x2 Array{Int64,2}:
>  1  2
>  3  4
>  5  6
>
> julia> vector(a)[3]=0
> 0
>
> julia> a
> 3x2 Array{Int64,2}:
>  1  2
>  3  4
>  0  6
>
> Am Samstag, 11. Oktober 2014 22:33:30 UTC+2 schrieb Peter Simon:
>>
>> It's not necessary because you can assign the result of reshape to the
>> same variable with virtually no overhead:
>>
>> julia> a = rand(1000,100,100);
>>
>> julia> @time a = reshape(a,prod(size(a)));
>> elapsed time: 1.1732e-5 seconds (336 bytes allocated)
>>
>> --Peter
>>
>> On Saturday, October 11, 2014 1:20:13 PM UTC-7, Stephan Buchert wrote:
>>>
>>> julia> a=[1 2; 3 4; 5 6]
>>> 3x2 Array{Int64,2}:
>>>  1  2
>>>  3  4
>>>  5  6
>>>
>>> julia> b=reshape(a, prod(size(a)));
>>>
>>> julia> b[3]=0
>>> 0
>>>
>>> julia> a
>>> 3x2 Array{Int64,2}:
>>>  1  2
>>>  3  4
>>>  0  6
>>>
>>>

Reply via email to