Thanks for your suggestion, Charles. That certainly works, but something a
little more general would be nice.
Erik, copy(a)[:] + 1 still gives me an Array{Any,1}.
Chris
On Friday, December 4, 2015 at 9:09:46 PM UTC-5, Erik Schnetter wrote:
>
> You can write
>
> copy(a)[:] + 1
>
> The expression `a + 1` implicitly makes a copy of the array, adding one to
> each element. The expression above does the same, but is more explicit
> about the indexing, and thus keeps the types the same. In particular, my
> expression
> - first makes a copy of `a`
> - then adds `1`, element-wise (thus not changing the array type
> - then returns the array
>
> -erik
>
>
> On Fri, Dec 4, 2015 at 8:48 PM, Charles Novaes de Santana <
> [email protected] <javascript:>> wrote:
>
>> As you probably noted, I suggested a wrong function :( Sorry, I copied
>> and pasted and didn't read
>>
>> here is the function I would like to suggest you:
>>
>> julia> function newsum(a::Array{Array{Int64,1},1}, i::Int)
>> lengtha = size(a,1);
>> return(a + [[i,i] for j = 1:lengtha])
>> end
>> newsum (generic function with 1 method)
>>
>> julia> newsum(a,1)
>> 5-element Array{Array{Int64,1},1}:
>> [2,2]
>> [2,2]
>> [2,2]
>> [2,2]
>> [2,2]
>>
>> best,
>>
>> Charles
>>
>>
>> On 5 December 2015 at 02:45, Charles Novaes de Santana <
>> [email protected] <javascript:>> wrote:
>>
>>> Hi Chris,
>>>
>>> Unfortunately I don't know why the type changes from
>>> Array{Array{Int64,1},1}
>>> to Array{Any,1}. But I have a suggestion to what you can do to keep it as
>>> Array{Array{Int64,1},1}.
>>>
>>> My initial shot would be to do a + [[1,1] for i = 1:5] instead of a + 1:
>>>
>>> julia> a + [[1,1] for i = 1:5]
>>> 5-element Array{Array{Int64,1},1}:
>>> [2,2]
>>> [2,2]
>>> [2,2]
>>> [2,2]
>>> [2,2]
>>>
>>> Or, if you want to simplify the way you do it, just define a function
>>> like this:
>>>
>>> julia> function newsum(a::Array{Array{Int64,1},1}, i::Int)
>>> lengtha = size(a,1);
>>> return([[i,i] for i = 1:lengtha])
>>> end
>>> newsum (generic function with 1 method)
>>>
>>> julia> newsum(a,1)
>>> 5-element Array{Array{Int64,1},1}:
>>> [1,1]
>>> [2,2]
>>> [3,3]
>>> [4,4]
>>> [5,5]
>>>
>>> But I am sure you will find many more suggestions here! ;)
>>>
>>> Best,
>>>
>>> Charles
>>>
>>> On 5 December 2015 at 02:16, Chris <[email protected] <javascript:>>
>>> wrote:
>>>
>>>> I am confused about the following:
>>>>
>>>> julia> a = [[1,1] for i = 1:5]
>>>> 5-element Array{Array{Int64,1},1}:
>>>> [1,1]
>>>> [1,1]
>>>> [1,1]
>>>> [1,1]
>>>> [1,1]
>>>>
>>>> julia> a + 1
>>>> 5-element Array{Any,1}:
>>>> [2,2]
>>>> [2,2]
>>>> [2,2]
>>>> [2,2]
>>>> [2,2]
>>>>
>>>> Specifically, why does the type change from Array{Array{Int64,1},1} to
>>>> Array{Any,1}, and what can I do to keep it as Array{Array{Int64,1},1}?
>>>>
>>>> Thanks,
>>>> Chris
>>>>
>>>
>>>
>>>
>>> --
>>> Um axé! :)
>>>
>>> --
>>> Charles Novaes de Santana, PhD
>>> http://www.imedea.uib-csic.es/~charles
>>>
>>
>>
>>
>> --
>> Um axé! :)
>>
>> --
>> Charles Novaes de Santana, PhD
>> http://www.imedea.uib-csic.es/~charles
>>
>
>
>
> --
> Erik Schnetter <[email protected] <javascript:>>
> http://www.perimeterinstitute.ca/personal/eschnetter/
>