(1 2 3 4 5) (2}"1)X=.i.5 5 Why does the above not work? I want to replace the 2nd column of X without having to do a transpose
cheers Roelof Dr. Roelof K. Brouwer PEng PhD http://www.tru.ca/faculty/rbrouwer Professor Emeritus School of Advanced Technologies and Mathematics Thompson Rivers University 900 McGill Road, PO Box 3010 Kamloops, BC, Canada,V2C 5N3 1 250 374 5874 home 1 250 828 5219 work 1 250 377 6133 fax email [EMAIL PROTECTED] -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rob Hodgkinson Sent: February 26, 2008 10:52 PM To: General forum Subject: Re: [Jgeneral] equivalence in boxed data In <mydata> each box contains a 1 element vector... $each mydata +-+-+-+-+-+-+-+-+-+-+ |1|1|1|1|1|1|1|1|1|1| +-+-+-+-+-+-+-+-+-+-+ In <lin> each box contains a scalar (atom with no shape) $each lin +++++++++++ ||||||||||| +++++++++++ When you test each variable against the test item of <'1', the shape doesn't match in mydata, but does in lin: mydata = <'1' 0 0 0 0 0 0 0 0 0 0 lin = <'1' 0 1 0 0 0 0 0 0 0 0 Likewise if you test against a test item of <,'1' vice versa: mydata = <,'1' 0 1 0 0 0 0 0 0 0 0 lin = <,'1' 0 0 0 0 0 0 0 0 0 0 You can also apply the verb '=' within each box, so try this ... ]mydata1 =: 'test1';(2 3$'1234');'not 1 to test' +-----+---+-------------+ |test1|123|not 1 to test| | |412| | +-----+---+-------------+ '1' =&.> mydata1 NB. This tests for '1' inside each box ... +---------+-----+-------------------------+ |0 0 0 0 1|1 0 0|0 0 0 0 1 0 0 0 0 0 0 0 0| | |0 1 0| | +---------+-----+-------------------------+ Note =&.> can use the cover name 'each' (for &.>) as follows: '1' = each mydata1 +---------+-----+-------------------------+ |0 0 0 0 1|1 0 0|0 0 0 0 1 0 0 0 0 0 0 0 0| | |0 1 0| | +---------+-----+-------------------------+ When you use {. you need to apply it within each box: ({. each mydata)=<'1' 0 1 0 0 0 0 0 0 0 0' Hope this helps.../Rob Hodgkinson On 27/02/08 4:21 PM, "The World" <[EMAIL PROTECTED]> wrote: > I've been playing with the readcvs function and am having a problem with > the boxed data. I can read in a 2 dimensional array of boxed character > data. I can select any particular column using > > col =. idx {"_1 myboxeddata > > The problem comes in when I want to test each of the boxes in the column > to see which one is equal to the single number 1 (as a character of > course). I would like to generate an array of 1s and 0s, the 1s being > where the number 1 character is. I would like to do this in the > following fashion > > col = <'1' > > But I always get 0s as the answer even though the boxed list contains a > single boxed 1 character > > I've recreated the problem in simpler form: > > mydata =. |: ;: 1 ]\'0123456789' > mydata > │0│1│2│3│4│5│6│7│8│9│ > > mydata = <'1' > 0 0 0 0 0 0 0 0 0 0 > > $mydata > 1 10 > > So because this horizontal format of mydata was transposed from a column > the shape is a little different than if I built this directly using ; > > lin =. '0';'1';'2';'3';'4';'5';'6';'7';'8';'9' > lin > │0│1│2│3│4│5│6│7│8│9│ > $lin > 10 > lin = <'1' > 0 1 0 0 0 0 0 0 0 0 > > which works the way I suspect. Even if I use take ({.) to get the > dimensions of the boxed list mydata the same as lin in the previous > example I still get all 0s: > > {. mydata > │0│1│2│3│4│5│6│7│8│9│ > ${. mydata > 10 > ({. mydata) = <'1' > 0 0 0 0 0 0 0 0 0 0 > > So what is going on here that I am missing? > > > > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
