1

Update

In short, I have myCAans[[1 ;; 5]] like this:

{{0, 0, 0, True, 0, 0, 0, 0, True, 0, "T0", 39}, {0, 0, 0, True, 0, 0, 0, 1, True, 1, "B", 101500}, {0, 0, 0, True, 0, 0, 0, 2, True, 2, "B", 100}, {0, 0, 0, True, 0, 0, 0, 3, True, 3, "B", 1000}, {0, 0, 0, True, 0, 0, 0, 4, True, 4, "B", 1000}}

Dimensions[myCAans]

{3000, 12}

Each line of

Total[ Select[myCAans , #[[5]] == 0 && #[[10]] == 0 &][[;; , 12]] ]
Total[ Select[myCAans , #[[5]] == 0 && #[[10]] == 1 &][[;; , 12]] ]
Total[ Select[myCAans , #[[5]] == 0 && #[[10]] == 2 &][[;; , 12]] ]
Total[ Select[myCAans , #[[5]] == 1 && #[[10]] == 0 &][[;; , 12]] ]
Total[ Select[myCAans , #[[5]] == 5 && #[[10]] == 6 &][[;; , 12]] ]

works fine.

I would like to know how to efficiently find

Total[ Select[myCAans , #[[5]] == i && #[[10]] == j &][[;; , 12]] ]

for i from 0 to 3 and j from 0 to 3 for example. Something like

Total[ Select[myCAans , #[[5]] == i && #[[10]] == j &][[;; , 12]] ] -> XXXXXX  <- Table[{i, j}, {i, 0, 3}, {j, 0, 3}]

OP

On a related question here, I am struggling to get my head around for this:

f@Table[{i, j}, {i, 0, 3}, {j, 0, 3}]
f @@ Table[{i, j}, {i, 0, 3}, {j, 0, 3}]
f @@@ Table[{i, j}, {i, 0, 3}, {j, 0, 3}]
f /@ Table[{i, j}, {i, 0, 3}, {j, 0, 3}]

Map[f, Table[{i, j}, {i, 0, 3}, {j, 0, 3}], {2, 2}]

MapAt[f, Table[{i, j}, {i, 0, 3}, {j, 0, 3}], {1}] // TableForm
MapAt[f, Table[{i, j}, {i, 0, 3}, {j, 0, 3}], {2, 1}] // TableForm
MapAt[f, Table[{i, j}, {i, 0, 3}, {j, 0, 3}], {2, 2}] // TableForm
MapAt[f, Table[{i, j}, {i, 0, 3}, {j, 0, 3}], {2, 3}] // TableForm

Map[f, Table[{i, j}, {i, 0, 3}, {j, 0, 3}], {1}] // TableForm
Map[f, Table[{i, j}, {i, 0, 3}, {j, 0, 3}], {2, 1}] // TableForm
Map[f, Table[{i, j}, {i, 0, 3}, {j, 0, 3}], {2, 2}] // TableForm
Map[f, Table[{i, j}, {i, 0, 3}, {j, 0, 3}], {2, 3}] // TableForm

Even this

MatrixFunction[f, Table[{i, j}, {i, 0, 3}, {j, 0, 3}]]

The desired output is

Table[f[i, j], {i, 0, 3}, {j, 0, 3}] // TableForm

{{f[0, 0], f[0, 1], f[0, 2], f[0, 3]}, {f[1, 0], f[1, 1], f[1, 2], f[1, 3]}, {f[2, 0], f[2, 1], f[2, 2], f[2, 3]}, {f[3, 0], f[3, 1], f[3, 2], f[3, 3]}}

Final aim is to apply a pure function which takes two inputs over an array, like this

enter image description here

In163 is one of many trials without a success. I have tested

Total[Select[myCAans, (#[[5]] == 0 && #[[10]] == 0) &][[;; , 12]]]
Total[Select[myCAans, (#[[5]] == 0 && #[[10]] == 1) &][[;; , 12]]]
Total[Select[myCAans, (#[[5]] == 0 && #[[10]] == 2) &][[;; , 12]]]
Total[Select[myCAans, (#[[5]] == 0 && #[[10]] == 3) &][[;; , 12]]]




Total[Select[myCAans, (#[[5]] == 3 && #[[10]] == 3) &][[;; , 12]]]

which all works perfectly fine.

Any more examples where I can pick up mapping pure functions, using /@ @@ and &/@ much easier and faster?

Thanks.

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Chen Stats Yu
  • 4,986
  • 2
  • 24
  • 50

0 Answers0