MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Summing above diagonal in a tensor

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112588] Summing above diagonal in a tensor
  • From: Alice Lesser <alice.lesser at bwin.org>
  • Date: Tue, 21 Sep 2010 02:05:25 -0400 (EDT)

Hi group,

Summing the elements of a matrix which are above the diagonal is easy:

m = Table[Subscript[a, x, y], {x, 1, 3}, {y, 1, 3}]
Total[UpperTriangularize[m, 1], 2]

gives
a_1,2 + a_1,3 + a_2,3
of course.

If I instead have a 4-dim tensor

t = Table[ Subscript[a, x, y, z, q], {x, 1, 3}, {y, 1, 3}, {z, 1, 3}, {q, 1, 3}]

is there a nifty way to get the sum of the elements which are above
the diagonal in the outer matrix and above the diagonal in the submatrices?
In other words I'm looking for the sum

a_1,2,1,2 + a_1,2,1,3 + a_1,2,2,3 + a_1,3,1,2 + a_1,3,1,3 + a_1,3,2,3+ a_2, 3,1,2 + a_2,3,1,3 + a_2,3,2,3

UpperTriangularize only seems to work on matrices, not tensors.
I could of course solve this with a few ugly for-loops, but it would be nice to know if there is a better way.

Thanks,
Alice



  • Prev by Date: Re: how implement a rule
  • Next by Date: Re: create character listing
  • Previous by thread: Re: should Positive[ complexNumber ] return undefined instead of False?
  • Next by thread: Re: Summing above diagonal in a tensor