RE: checking for a particular value in a matrix

*To*: mathgroup at smc.vnet.net*Subject*: [mg31467] RE: [mg30933] checking for a particular value in a matrix*From*: Au Han Bin <auhb3 at cz3.nus.edu.sg>*Date*: Wed, 7 Nov 2001 05:29:58 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

does anyone understand what does Flatten does? the help file just tells me that it flattens. somehoww, it does not actually define what flatten does? regards, joshua_au at hotmail.com On Thu, 27 Sep 2001, David Park wrote: > This code will check that there is exactly one entry in a matrix of value 1. > > ExactlyOneOne[(mat_)?MatrixQ] := > Count[mat, 1, Infinity] == 1 > > testmat1 = {{1, 0}, {2, 3}}; > testmat2 = {{1, 0}, {2, 1}}; > testmat3 = {{-1, 0}, {2, 3}}; > > ExactlyOneOne /@ {testmat1, testmat2, testmat3} > {True, False, False} > > As for your second question, use a DelayedSet (:=). When you use Set (=) > Mathematica calculates the right hand side of the definition immediately - > even though the symbol a appears on the left hand side. This is a confusing > aspect of Mathematica definitions that trips up many users. I don't know why > Mathematica can't check to see if the symbol appears on the lhs. There is > probably some logic to it. > > David Park > djmp at earthlink.net > http://home.earthlink.net/~djmp/ > > > > From: Au Han Bin [mailto:auhb3 at cz3.nus.edu.sg] To: mathgroup at smc.vnet.net > > > > Hi, I am a programming newbie and I need advice on how to check that a > > table or matrix , for all nonzero entries in a given row, has only one > > entry of value 1. > > > > > > > > i have another query on why the code below does not work, when i call > > convert{1,0,0,0} again, the results given are from an earlier question, > > e.g. {1,1} is it initialised wrongly? > > > > > > Clear[a,convert]; > > convert[a___] = Sum[a[[i]]*2^(Length[a]-i),{i,1,Length[a]}] > > > > regards, thanks, > > > > joshua > > > > > >