2
$\begingroup$

i use Mathematica 9.0 and I want to know, how to accumulate more lists, in the same position ... First of all u have to know, that i can have 1000 lists with 100 elements... for example.

{{1,2,3,4},{1,5,2,3}}...

Now i want to plus all first elements and the 3rd... so i have a new list with

{2,5}

or all 3rd and 4th elements:

{5,7}... at the end i need to subtract all result with 100... so i have for the first example ... so this can be a big combination... all first and 4th oder 2nd and 3rd oder first and 4th ... an so on

{{2,5},{98,95}}... At the end i create a 2x2 matrix and calculate the sums of rows and list... so this is very easy but if u have 1000 lists with 100 elements, it will be a little harder...

i hope u can help me

$\endgroup$

1 Answer 1

2
$\begingroup$
list = {{1, 2, 3, 4}, {1, 5, 2, 3}};

Total @ list[[All, {1, 3}]]

{2, 5}

For multiple totals you can do

Total @ list[[All, #]] & /@ {{1, 3}, {1, 4}}

{{2, 5}, {2, 7}}

To also answer your additional request:

{#, 100 - #} &[Total@list[[All, {1, 3}]]]

{{2, 5}, {98, 95}}

$\endgroup$
5
  • 1
    $\begingroup$ Also: Total[list[[All, {1, 3}]], {1}]. $\endgroup$
    – MarcoB
    Aug 21, 2017 at 16:10
  • $\begingroup$ But what if i want to do it for the 1st and 4th to.. so all same time? $\endgroup$
    – Mudy Fa
    Aug 21, 2017 at 16:11
  • $\begingroup$ See updated answer $\endgroup$
    – eldo
    Aug 21, 2017 at 16:16
  • $\begingroup$ But if i subtract them with 100, i cant create a matrix... because they aren in the right position... i need something like: {{2,5},{98,95}} and so on... $\endgroup$
    – Mudy Fa
    Aug 21, 2017 at 16:37
  • $\begingroup$ Thanks for ur help! I didnt get it, how to create a 2x2 matrix for a pair... u know for the first and 4th and the same thing on the 3rd and 4th... $\endgroup$
    – Mudy Fa
    Aug 21, 2017 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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