Re: checking for a particular value in a matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg31672] Re: checking for a particular value in a matrix
- From: "Lawrence A. Walker Jr." <lwalker701_remove_ at earthlink.net>
- Date: Fri, 23 Nov 2001 05:47:21 -0500 (EST)
- Organization: Morgan State University, COMSARE
- References: <9sb493$bn9$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, Flatten[] removes all of the curly braces '{ }' inside a list. Curly braces inside a list are said to demarcate objects that are at deeper levels in the list. Objects at deeper levels in a list can be accessed by listname[[i,j,..]]. However, if flatten is used then all of the objects within the list are at the first level. So listname[[i]] can be used to access any element within the list. Hope this helps, Lawrence Au Han Bin wrote: > 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 >>> >>> >>> >> > >