RE: random matrix initialisation...
- To: mathgroup at smc.vnet.net
- Subject: [mg37619] RE: [mg37576] random matrix initialisation...
- From: "DrBob" <drbob at bigfoot.com>
- Date: Wed, 6 Nov 2002 06:58:06 -0500 (EST)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
X = Partition[Sort[Join[Table[1, {#2}], Table[0, {#1^2 - #2}]],
Random[] > 0.5 &], #1] &;
X[4, 3]
DrBob
-----Original Message-----
From: Manuel Marques-Pita [mailto:manuxu at mac.com]
To: mathgroup at smc.vnet.net
Subject: [mg37619] [mg37576] random matrix initialisation...
hello,
i have a question regarding matrices. searched on the web and forums
but maybe due to using wrong keywords i am not finding an answer...
i need a way or function X to initialise matrices in mathematica such
that each time i call X i get a matrix with a predetermined number of
elements initialised as "1" and the rest as "0"
examples
X(4,3)
{{0,0,0,0}, {0,0,1,0}, {0,0,0,1}, {1,0,0,0}}
again X(4,3)
{{1,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,1,0,0}}
etc.. (first argument means that the matrix is 4x4 and second means
that there should be 3 "1's" present in the matrix
any help, pointers, etc will be appreciated!
thanks a lot
m
--