I have a list
a={1,2,3,4,5}
I want to calculate absolute differences of each element with all other elements
b={{0,1,2,3,4},{1,0,1,2,3},{2,1,0,1,2},{3,2,1,0,1},{4,3,2,1,0}}
and then calculate the total for each subarray
c={10,7,6,7,10}
I want to write it in one line basically, need help here
b=[#1-a]&/@a isn't working.
Do someone has an easy way to write it out, instead of using any module loop? thanks in advance
[]
used for passing arguments to functions (e.g.Abs
), you almost got it:Abs[#1 - a] & /@ a
. $\endgroup$CentralFeature[a]
. For graphs it'sGraphCenter[g]
and for geometric dataSpatialMedian[a]
(not necessarily a point in your set, though in your example it would have been 3). $\endgroup$