comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Sum along diagonals
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Sum along diagonals [message #21449 is a reply to message #21441] Fri, 25 August 2000 19:28 Go to previous messageGo to previous message
jph is currently offline  jph
Messages: 2
Registered: September 1999
Junior Member
I hope you folks realize you are using the wrong
language for this sort of thing. :-) To see what a *real*
array language does with this, look at the "J" solution
(J's a sort of APL in ASCII: http://www.jsoftware.com/)

NB. define a 4x4 matrix:
M=. i. 4 4
NB. display it:
M
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15

NB. sum the diagonals:

+//. M
0 5 15 30 30 25 15

NB. Yes, that's it: +//. is the code!
NB. It doesn't have to be square:

M=. i. 4 6
M
0 1 2 3 4 5
6 7 8 9 10 11
12 13 14 15 16 17
18 19 20 21 22 23
+//. M
0 7 21 42 46 50 48 39 23

I know, it's got nothing to do with IDL, but I couldn't
resist. Actually, I use J to compute things & IDL to
display the results....

J. Patrick Harrington


In article <mole6e23-2508001450050001@checont6.ucsd.edu>, mole6e23@hotmail.com (Todd Clements)
|>
|> Every once in a while (not often enough to make me worry about optimizing
|> too much), I want to take a not necessarily square matrix and get the sum
|> along the diagonals, such as the following, with the theoretical function
|> sum_diag:
|>
|> IDL> blah = indgen( 4, 4 )
|> IDL> print, blah
|> 0 1 2 3
|> 4 5 6 7
|> 8 9 10 11
|> 12 13 14 15
|> IDL> print, sum_diag( blah )
|> 0 5 15 30 30 25 15
|>
|> which is the series [0, 4+1, 8+5+2, 12+9+6+3, ... ]
|>
|> Of course, to be difficult, I'd like it to work for non-square matrices as well:
|>
|> IDL> blah = indgen( 5, 3 )
|> IDL> print,blah
|> 0 1 2 3 4
|> 5 6 7 8 9
|> 10 11 12 13 14
|>
|> and the result would be the series [0, 5+1, 10+6+2, 11+7+3, ... ]
|>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Texture mapping onto DEM
Next Topic: Re: IDL 5.2 array definition question.

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 06:21:08 PDT 2025

Total time taken to generate the page: 0.31530 seconds