Re: [julia-users] Re: How would you implement setindices! elegenatly?

2016-10-26 Thread Cedric St-Jean
Ah, right, I hadn't read your definition carefully.

A[[CartesianIndex(1,1), CartesianIndex(2,3)]] = [0,0]

Seems to be working correctly. So given your ind matrix, we can do

A[mapslices(s->CartesianIndex(s...), ind, 2)]

but I doubt that it'll be very performant. Could you directly output
CartesianIndex objects?

On Wed, Oct 26, 2016 at 4:11 PM, Tsur Herman  wrote:

> julia> A=rand(4,4)
> 4×4 Array{Float64,2}:
>  0.427998   0.720987  0.375013  0.432887
>  0.0333443  0.602459  0.946685  0.817995
>  0.402635   0.571399  0.553542  0.0234215
>  0.707829   0.339795  0.451387  0.358248
>
>
> julia> ind = [1 1; 2 2; 3 3]
> 3×2 Array{Int64,2}:
>  1  1
>  2  2
>  3  3
>
>
> julia> A[ind]
> 3×2 Array{Float64,2}:
>  0.427998   0.427998
>  0.0333443  0.0333443
>  0.402635   0.402635
>
>
>
> julia>
>
> On Wednesday, October 26, 2016 at 6:19:45 PM UTC+3, Cedric St-Jean wrote:
>>
>> A[indices] = Values
>>
>> ?
>>
>> On Wednesday, October 26, 2016 at 9:53:17 AM UTC-4, Tsur Herman wrote:
>>>
>>> What would you suggest is a fast and elegant way to achieve indexing
>>> into an array using a set of indices?
>>>
>>> function setindices!(A,Values,Indices)
>>> assert(length(Values) == size(Indices,1))
>>> for i=1:length(Values)
>>> setindex!(A,Values[i],(Indices[i,:]...)...)
>>> end
>>> end
>>>
>>> I am currently using this function and I was wondering whether I missed
>>> something.
>>>
>>>


[julia-users] Re: How would you implement setindices! elegenatly?

2016-10-26 Thread Tsur Herman
julia> A=rand(4,4)
4×4 Array{Float64,2}:
 0.427998   0.720987  0.375013  0.432887
 0.0333443  0.602459  0.946685  0.817995
 0.402635   0.571399  0.553542  0.0234215
 0.707829   0.339795  0.451387  0.358248


julia> ind = [1 1; 2 2; 3 3]
3×2 Array{Int64,2}:
 1  1
 2  2
 3  3


julia> A[ind]
3×2 Array{Float64,2}:
 0.427998   0.427998
 0.0333443  0.0333443
 0.402635   0.402635



julia>

On Wednesday, October 26, 2016 at 6:19:45 PM UTC+3, Cedric St-Jean wrote:
>
> A[indices] = Values
>
> ?
>
> On Wednesday, October 26, 2016 at 9:53:17 AM UTC-4, Tsur Herman wrote:
>>
>> What would you suggest is a fast and elegant way to achieve indexing into 
>> an array using a set of indices?
>>
>> function setindices!(A,Values,Indices)
>> assert(length(Values) == size(Indices,1))
>> for i=1:length(Values)
>> setindex!(A,Values[i],(Indices[i,:]...)...)
>> end
>> end
>>
>> I am currently using this function and I was wondering whether I missed 
>> something.
>>
>>

[julia-users] Re: How would you implement setindices! elegenatly?

2016-10-26 Thread Cedric St-Jean
A[indices] = Values

?

On Wednesday, October 26, 2016 at 9:53:17 AM UTC-4, Tsur Herman wrote:
>
> What would you suggest is a fast and elegant way to achieve indexing into 
> an array using a set of indices?
>
> function setindices!(A,Values,Indices)
> assert(length(Values) == size(Indices,1))
> for i=1:length(Values)
> setindex!(A,Values[i],(Indices[i,:]...)...)
> end
> end
>
> I am currently using this function and I was wondering whether I missed 
> something.
>
>