Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14752 > unrolled thread

Re: Adding value to some elements of a list

Started byAdriano Pascoletti <adriano.pascoletti@uniud.it>
First post2013-06-05 08:33 +0000
Last post2013-06-06 11:25 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Adding value to some elements of a list Adriano Pascoletti <adriano.pascoletti@uniud.it> - 2013-06-05 08:33 +0000
    Re: Adding value to some elements of a list Joerg Lenhardt <joerg.lenhardt@FernUni-Hagen.de> - 2013-06-06 11:25 +0000

#14752 — Re: Adding value to some elements of a list

FromAdriano Pascoletti <adriano.pascoletti@uniud.it>
Date2013-06-05 08:33 +0000
SubjectRe: Adding value to some elements of a list
Message-ID<komt58$31g$1@smc.vnet.net>
In[1]:= a = {10, 20, 30, 40, 50, 60};
b = {2, 4, 6};
a[[b]] = a[[b]] + 17;
a
Out[4]= {10, 37, 30, 57, 50, 77}


Adriano Pascoletti


2013/6/5 Joerg Lenhardt <joerg.lenhardt@fernuni-hagen.de>

> Hello,
>
> I have two lists. One containing values, another containing indexes to
> the first list. I want to add a value to all elements of the first list
> when its index is in the second list:
>
> a={10,20,30,40,50,60}
>
> b={2,4,6}
>
> c=17
>
> ==>
>
> {10,20+17,30,40+17,50,60+17}
>
> I would be glad if anyone have a simple solution for that problem - I am
> convinced there is one ...
>
> Best regards
> J. Lenhardt
>
>

[toc] | [next] | [standalone]


#14762

FromJoerg Lenhardt <joerg.lenhardt@FernUni-Hagen.de>
Date2013-06-06 11:25 +0000
Message-ID<kopriq$chb$1@smc.vnet.net>
In reply to#14752
Thanks to all for your support. It worked.

On 05.06.13 08:33, Adriano Pascoletti wrote:
> In[1]:= a = {10, 20, 30, 40, 50, 60};
> b = {2, 4, 6};
> a[[b]] = a[[b]] + 17;
> a
> Out[4]= {10, 37, 30, 57, 50, 77}
> 
> 
> Adriano Pascoletti
> 
> 
> 2013/6/5 Joerg Lenhardt <joerg.lenhardt@fernuni-hagen.de>
> 
>> Hello,
>>
>> I have two lists. One containing values, another containing indexes to
>> the first list. I want to add a value to all elements of the first list
>> when its index is in the second list:
>>
>> a={10,20,30,40,50,60}
>>
>> b={2,4,6}
>>
>> c=17
>>
>> ==>
>>
>> {10,20+17,30,40+17,50,60+17}
>>
>> I would be glad if anyone have a simple solution for that problem - I am
>> convinced there is one ...
>>
>> Best regards
>> J. Lenhardt
>>
>>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web