1
$\begingroup$

I have a list given as:

d={{{1,1,1},{10,10,10}},{{70,70,70},{51,51,51},{97,97,97}},{{7,7,7}}}

Each number in the list represents a potential "W" value for the following fraction and each sublist is a generation (multiple triplets can be found in one generation). I also have an equation given by:

eq= w/1000

What I'd like to do is perform a looping summation where the first generation (.i.e {{{1,1,1},{10,10,10}}} is not included in any calculations, only generations from 2 on-wards are counted. I'm trying to take each value from list "d" and insert them as "w" given by "eq" and sum them so that I obtain an output which looks like this:

output= {{{},{{70/1000+ 70/1000 +70/1000 + 51/1000 + 51/1000 + 51/1000 + 97/1000 + 97/1000 + 97/1000}},{{7/1000 + 7/1000+ 7/1000}}}

Is there a quick way to do this without having to use a For loop?

$\endgroup$
1
  • 1
    $\begingroup$ d // TreeForm shows it's structure, if it helps? $\endgroup$
    – prog9910
    Jun 3, 2020 at 18:08

2 Answers 2

2
$\begingroup$

My two cents.

In[5]:= Flatten[Map[#/1000&,Rest[d]]]
Out[5]= (* Out: {7/100,7/100,7/100,51/1000,51/1000,51/1000,97/1000,97/1000,97/1000,7/1000,7/1000,7/1000} *)

In[6]:= Total[Flatten[Map[#/1000&,Rest[d]]]]
(* Out[6]= 27/40 *)
```
$\endgroup$
2
$\begingroup$
Total[Rest[Total[d, {2}]], {2}]/1000
{327/500, 21/1000}

The innermost Total adds up all the terms at the second level. The Rest removes the first item (which you explicitly wanted discarded) and the outer Total adds up the remaining terms.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.