You've already posted the simple solutions, but just for variation,
here are two less simple ones. These should work for any numeric
list.
(|.@{."0~#\) 3 1 4 1 5
3 0 0 0 0
0 1 0 0 0
0 0 4 0 0
0 0 0 1 0
0 0 0 0 5
(-@#{.{:)\ 3 1 4 1 5
3 0 0 0 0
0 1 0 0 0
0 0 4 0 0
0 0 0 1 0
0 0 0 0 5
--
Am
Thanks for the shout out, but I feel obliged to confess that I stole that /:
trick from eesuk in the 2006 "zig zag order" thread.
http://www.jsoftware.com/pipermail/programming/2006-November/004156.html
(The moment I wrote that expression still stands out as one of the proudest of
my 12+ year J
See http://www.jsoftware.com/pipermail/programming/2008-October/012505.html
;)
On Thu, Feb 27, 2014 at 1:42 AM, Raul Miller wrote:
> Same as i.@# in =@i.@#
>
> It's generating a list of distinct values which = will use to
> construct an identity matrix.
>
> Mind you, it might have made more sen
See http://www.jsoftware.com/pipermail/programming/2008-October/012505.html
;)
On Thu, Feb 27, 2014 at 1:42 AM, Raul Miller wrote:
> Same as i.@# in =@i.@#
>
> It's generating a list of distinct values which = will use to
> construct an identity matrix.
>
> Mind you, it might have made more sen
:22 PM
To: Programming forum
Subject: Re: [Jprogramming] create matrix from diagonal
Several of the diag* verbs that I posted work on non-numerics as well. e.g.
diag3=: ,~@# $ ] #~ 1 j. #
diag3 'syzygy'
s
y
z
y
g
y
diag3 'triple';'word';'scor
(*=) doesn't work if items are repeated
(*=) 2 1 3 6
2 0 0 0
0 1 0 0
0 0 3 0
0 0 0 6OK
(*=) 2 1 3 1
|length error
| (*=)2 1 3 1 Fail
(*=@\:)2 1 3 1
2 0 0 0
0 1 0 0
0 0 3 0
0 0 0 1 OK
Don Kelly
On 26/02/2014 10:36 PM, Michal Wallace wrote:
What pur
On 2014.02.27 14:21:46, you,
the extraordinary Roger Hui, spake thus:
> Several of the diag* verbs that I posted work on non-numerics as well. e.g.
>
>diag3=: ,~@# $ ] #~ 1 j. #
Thanks! I had to go look up: (a j. b) #
--
Nollaig MacKenzie
http://www.yorku.ca/nollaig
-
Several of the diag* verbs that I posted work on non-numerics as well. e.g.
diag3=: ,~@# $ ] #~ 1 j. #
diag3 'syzygy'
s
y
z
y
g
y
diag3 'triple';'word';'score'
┌──┬┬─┐
│triple││ │
├──┼┼─┤
│ │word│ │
├──┼┼─┤
│ │
(I'm dangling this off the meg that started the thread)
Is there a clever way of doing this for non-numeric strings?
I couldn't think of a way to start on a tacit solution; dg0
is clear but not noticeably clever or fast:
dg0=: 3 : 0
nn=. # y
inds=. <"1@:(<"0) ,.~ i. nn
M=.(,~ nn)$ 1{.0{. y
y inds
Speaking of palindromes, I can not miss telling y'all the following Eugene
McDonnell anecdote as related by Bob Bernecky:
Eugene walked into my office at The Exchange Tower one
afternoon, to find me on a telephone call. He wrote the following
on the blackboard, smiled seraphically, and walked out.
o: "programm...@jsoftware.com"
> Cc:
> Sent: Thursday, February 27, 2014 12:48:44 AM
> Subject: Re: [Jprogramming] create matrix from diagonal
>
> even shorter:
>
>diag4=: *=@\:
>
>diag4 9 7 5 3
> 9 0 0 0
> 0 7 0 0
> 0 0 5 0
> 0 0 0 3
>
: Thursday, February 27, 2014 12:48:44 AM
Subject: Re: [Jprogramming] create matrix from diagonal
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
em.
Linda
-Original Message-
From: programming-boun...@forums.jsoftware.com
[mailto:programming-boun...@forums.jsoftware.com] On Behalf Of David Lambert
Sent: Thursday, February 27, 2014 7:09 AM
To: programming
Subject: Re: [Jprogramming] create matrix from diagonal
You've already
14 22:02:00 -0500
>>From: Joe Bogner
>>To: programm...@jsoftware.com
>>Subject: [Jprogramming] create matrix from diagonal
>>Message-ID:
>>
>>Content-Type: text/plain; charset=ISO-8859-1
>
>>
>>I'm experimenting with svd and am looking for a
You've already gotten several solutions. This is a good time to learn
of the j essays.
http://www.jsoftware.com/jwiki/Essays/Identity%20Matrix
>Date: Wed, 26 Feb 2014 22:02:00 -0500
>From: Joe Bogner
>To: programm...@jsoftware.com
>Subject: [Jprogramming] create mat
You can always use ~. =/ ]
a=: 'wontipanicinapitnow'
'-0' {~ = a
0-0
-0---0-
--00---00--
---0---0---
0---0-0---0
-0---0-
--0-0--
-0-
'-0' {~ (~. =/ ]) a
0-0
-0---0-
--
D'oh. I realized what it was for a few minutes later, and came back hoping
everyone was asleep and I could answer myself.
Ah well. :)
On Thu, Feb 27, 2014 at 12:42 AM, Raul Miller wrote:
>
> Mind you, it might have made more sense for = to always construct
> identity matrices.
>
But then how wo
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
= 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
wrote:
> What purpose does the \: serve there?
>
Same as i.@# in =@i.@#
It's generating a list of distinct values which = will use to
construct an identity matrix.
Mind you, it might have made more sense for = to always construct
identity matrices.
But in terms of time, constructing an identity matrix is O(n^2) and \:
is O(n log n) or better (
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
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
Bravo.
On Wed, Feb 26, 2014 at 9:48 PM, J. Patrick Harrington
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 M
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 wrote:
diag=: 3 : 'y (,&.>~i.#y)} 0 $~ ,~#y
Yup. Amalgating the ideas in diag1 and expressions by Don Guinn and Kip
Murray:
diag1a=: * =@i.@#
diag1a 10 20 30 40
10 0 0 0
0 20 0 0
0 0 30 0
0 0 0 40
See also http://www.jsoftware.com/jwiki/Essays/Identity_Matrix
On Wed, Feb 26, 2014 at 7:40 PM, km wrote:
> (*"0 1
(*"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 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
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
(*=/~@i.@#)4 3 2.23607 0
4 0 0 0
0 3 0 0
0 0 2.23607 0
0 0 0 0
On Wed, Feb 26, 2014 at 8:12 PM, Joe Bogner 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
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 wrote:
> I'm experimenting with svd and am looking for a nicer way of creating
> a matrix from the S diagonal
>
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 tri
29 matches
Mail list logo