That is nice!

Here is a slightly different variation

   f=: 3 : 0
((#y),(#y))$ y ((1+#y)* i. #y) } ,((#y),(#y))$ 0
)
   f 2 7 9 20
2 0 0  0
0 7 0  0
0 0 9  0
0 0 0 20


2008/10/12 Mike Day <[EMAIL PROTECTED]>

> This might well be in Roger's essay,  but it's so
> concise and beautiful that I can't resist sending
> it anyway!
>
>  (*=) 2 7 9 20   NB. I'm forcing a line throw
>
> 2 0 0  0
> 0 7 0  0
> 0 0 9  0
> 0 0 0 20
>
> Mike
>
>
> Roger Hui wrote:
>
>> http://www.jsoftware.com/jwiki/Essays/Identity_Matrix
>> may give you some ideas.  For the identity matrix itself
>> there are over 30 ways.
>>
>>
>>
>> ----- Original Message -----
>> From: Raul Miller <[EMAIL PROTECTED]>
>> Date: Saturday, October 11, 2008 11:40
>> Subject: [Jprogramming] diagonal arrays
>> To: Programming forum <[email protected]>
>>
>>
>>
>>> Given a vector, put it on the diagonal of an array:
>>>
>>>   (<0 1)&|:inv 2 7 9 20
>>> |index error
>>>   (+/ .*(e.(<0 1 2 )&|:)@i.@(3##)) 2 7 9 20
>>> 2 0 0  0
>>> 0 7 0  0
>>> 0 0 9  0
>>> 0 0 0 20
>>>   (, $~ 2##)@(,"0 1*&0)2 7 9 20
>>> 2 0 0  0
>>> 0 7 0  0
>>> 0 0 9  0
>>> 0 0 0 20
>>>
>>> Are there more concise approaches, that work?
>>>
>>>
>>
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database:
>> 270.8.0/1717 - Release Date: 09/10/2008 16:56
>>
>>
>>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Björn Helgason, Verkfræðingur
Fugl&Fiskur ehf,
Þerneyjarsundi 23, Hraunborgum
Po Box 127,801 Selfoss ,
t-póst: [EMAIL PROTECTED]
gsm: +3546985532
Landslags og skrúðgarðagerð, gröfuþjónusta
http://groups.google.com/group/J-Programming


Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans

góður kennari getur stigið á tær án þess að glansinn fari af skónum
         /|_      .-----------------------------------.
        ,'  .\  /  | Með léttri lund verður        |
    ,--'    _,'   | Dagurinn í dag                     |
   /       /       | Enn betri en gærdagurinn  |
  (   -.  |        `-----------------------------------'
  |     ) |        (\_ _/)
 (`-.  '--.)       (='.'=)
  `. )----'        (")_(")
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to