Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Adding value to some elements of a list
Replies: 5   Last Post: Jun 6, 2013 11:14 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Sseziwa Mukasa

Posts: 108
Registered: 8/26/07
Re: Adding value to some elements of a list
Posted: Jun 6, 2013 7:24 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On option:

(Debug) In[1]:= a = {10, 20, 30, 40, 50, 60};

b = {2, 4, 6};

c = 17;
(Debug) In[4]:= a[[#]] += c & /@ b
(Debug) Out[4]= {37, 57, 77}
(Debug) In[5]:= a
(Debug) Out[5]= {10, 37, 30, 57, 50, 77}

On Jun 5, 2013, at 3:27 AM, Joerg Lenhardt <joerg.lenhardt@FernUni-Hagen.de> wrote:

> 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
>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.