RE: random matrix initialisation...
- To: mathgroup at smc.vnet.net
- Subject: [mg37599] RE: [mg37576] random matrix initialisation...
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 6 Nov 2002 06:53:32 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Manuel, matX[size_Integer?Positive, ones_Integer?NonNegative] /; ones <= size^2 := Partition[ RandomPermutation[Join[Array[1 &, ones], Array[0 &, size^2 - ones]]], size] matX[4, 3] {{0, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}} matX[4, 3] {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 1, 1, 0}, {0, 0, 1, 0}} David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Manuel Marques-Pita [mailto:manuxu at mac.com] To: mathgroup at smc.vnet.net 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 --