BTW, the use of rank can obviate the need for creating a diagonal matrix:
 Post-multiplying by a diagonal matrix is the same as *"1, and
pre-multiplying by a diagonal matrix is the same as just * .  For example:

   diag=: * =@/:
   diag 1 10 100
1  0   0
0 10   0
0  0 100

   ] M=: i.3 4
0 1  2  3
4 5  6  7
8 9 10 11

   M +/ .* diag 1 10 100 1000
0 10  200  3000
4 50  600  7000
8 90 1000 11000
   M *"1 ] 1 10 100 1000
0 10  200  3000
4 50  600  7000
8 90 1000 11000

   (diag 1 10 100) +/ .* M
  0   1    2    3
 40  50   60   70
800 900 1000 1100
   1 10 100 * M
  0   1    2    3
 40  50   60   70
800 900 1000 1100



On Wed, Feb 26, 2014 at 10:44 PM, Roger Hui <[email protected]>wrote:

>    = 3 1 4 1 5 9
> 1 0 0 0 0 0
> 0 1 0 1 0 0
> 0 0 1 0 0 0
> 0 0 0 0 1 0
> 0 0 0 0 0 1
>    = \: 3 1 4 1 5 9
> 1 0 0 0 0 0
> 0 1 0 0 0 0
> 0 0 1 0 0 0
> 0 0 0 1 0 0
> 0 0 0 0 1 0
> 0 0 0 0 0 1
>
> /: would also have worked.
>
>
>
> On Wed, Feb 26, 2014 at 10:36 PM, Michal Wallace <[email protected]
> > wrote:
>
>> What purpose does the \: serve there?
>>
>>    (*=) 9 7 5 3
>>
>> 9 0 0 0
>>
>> 0 7 0 0
>>
>> 0 0 5 0
>>
>> 0 0 0 3
>>
>>
>>
>>
>> On Wed, Feb 26, 2014 at 11:48 PM, J. Patrick Harrington
>> <[email protected]>wrote:
>>
>> > even shorter:
>> >
>> >   diag4=: *=@\:
>> >
>> >   diag4 9 7 5 3
>> > 9 0 0 0
>> > 0 7 0 0
>> > 0 0 5 0
>> > 0 0 0 3
>> >               Patrick
>> >
>> >
>> > On Wed, 26 Feb 2014, km wrote:
>> >
>> >>    (*"0 1 =@i.@#) 1 2 3
>> >> 1 0 0
>> >> 0 2 0
>> >> 0 0 3
>> >>
>> >> --Kip Murray
>> >>
>> >> Sent from my iPad
>> >>
>> >>  On Feb 26, 2014, at 9:35 PM, Roger Hui <[email protected]>
>> >>> wrote:
>> >>>
>> >>>   diag=: 3 : 'y (,&.>~i.#y)} 0 $~ ,~#y'
>> >>>   diag 10 20 30 40
>> >>> 10  0  0  0
>> >>> 0 20  0  0
>> >>> 0  0 30  0
>> >>> 0  0  0 40
>> >>>
>> >>>   diag1=: ]\ * =/~@i.@#
>> >>>   diag1 10 20 30 40
>> >>> 10  0  0  0
>> >>> 0 20  0  0
>> >>> 0  0 30  0
>> >>> 0  0  0 40
>> >>>
>> >>>   diag2=: -@>:@i.@# {."0 ]
>> >>>   diag2 10 20 30 40
>> >>> 10  0  0  0
>> >>> 0 20  0  0
>> >>> 0  0 30  0
>> >>> 0  0  0 40
>> >>>
>> >>>   diag3=: ,~@# $ ] #~ 1 j. #
>> >>>   diag3 10 20 30 40
>> >>> 10  0  0  0
>> >>> 0 20  0  0
>> >>> 0  0 30  0
>> >>> 0  0  0 40
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>  On Wed, Feb 26, 2014 at 7:12 PM, Joe Bogner <[email protected]>
>> >>>> wrote:
>> >>>>
>> >>>> Sorry, I figured it out:
>> >>>>
>> >>>> I just needed one more 0...
>> >>>>
>> >>>>   ]  S * (4 4 $  1 0 0 0 0)
>> >>>> 4 0       0 0
>> >>>> 0 3       0 0
>> >>>> 0 0 2.23607 0
>> >>>> 0 0       0 0
>> >>>>
>> >>>>  On Wed, Feb 26, 2014 at 10:02 PM, Joe Bogner <[email protected]>
>> >>>>> wrote:
>> >>>>> I'm experimenting with svd and am looking for a nicer way of
>> creating
>> >>>>> a matrix from the S diagonal
>> >>>>>
>> >>>>> 4 3 2.23607 0
>> >>>>>
>> >>>>> needs to be
>> >>>>>
>> >>>>> ]   (4 4 $ 4 0 0 0 0 3 0 0 0 0 2.23607  0 0 0 0 0 )
>> >>>>> 4 0       0 0
>> >>>>> 0 3       0 0
>> >>>>> 0 0 2.23607 0
>> >>>>> 0 0       0 0
>> >>>>>
>> >>>>> What would be the idiomatic way to make that conversion? I tried
>> >>>>> various versions of reshape and insert.
>> >>>>>
>> >>>>> Not quite...
>> >>>>>
>> >>>>> ],\ S
>> >>>>> 4 0       0 0
>> >>>>> 4 3       0 0
>> >>>>> 4 3 2.23607 0
>> >>>>> 4 3 2.23607 0
>> >>>>>
>> >>>>> I also thought about multiplying it by a diagonal matrix of 0s and
>> 1s
>> >>>>> but couldn't get that figured out either
>> >>>>>
>> >>>>> Thanks
>> >>>>> Joe
>> >>>>>
>> >>>>
>> ----------------------------------------------------------------------
>> >>>> For information about J forums see
>> http://www.jsoftware.com/forums.htm
>> >>>>
>> >>> ----------------------------------------------------------------------
>> >>> For information about J forums see
>> http://www.jsoftware.com/forums.htm
>> >>>
>> >> ----------------------------------------------------------------------
>> >> For information about J forums see http://www.jsoftware.com/forums.htm
>> >>
>> >>  ----------------------------------------------------------------------
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> >
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to