in reply to constructing a matrix with perl

while(<>){ ($coords,$entry)=split; ($coord1,$coord2)=split 'v',$coords; $M{$coord1}{$coord2}=$entry; } print $M{AA}{CH},"\n"; #just to test
chas
(I'm not sure what you meant about "multiple results" or what you wanted to do in that case, so I didn't consider that.)
(Update: My apologies - I started thinking about the question and forgot to make make the matrix "symmetric" as you asked; however, I'm a bit confused about exactly how you want this handled because the matrix doesn't seem necessarily square (or am I misunderstanding?) You could certainly make a new matrix in a similar way, replacing various xy entries by (xy entry + yx entry)/2 if both entries exist. But what if they don't both exist?)

Replies are listed 'Best First'.
Re^2: constructing a matrix with perl
by Anonymous Monk on Feb 28, 2005 at 17:37 UTC
    yeah it should be a 39 by 39 square. there are 1,400 odd numbers - in my data - i suppose its symetrical accross a diagonal line of zeros, AAvAA, AEvAE.... ZHvZH.

    I havent included all the values here.

    I haven't actually got data for XvX pairs, where the values are zero - but it will be zero for the matrix. I do have all cases of YvX for any XvY.

    hope that clears things up - any more questions ask away! -thanks

      In that case, I would probably first create the square "matrix" with all entries initialized to 0. Then I would read in the data you have as in my previous reply. Finally, I would loop over the entries making them symmetric. To do this, you could make an array @A with entries AA,...,ZH and then do the symmetrizing over the matrix entries $M{$A[i]}{$A[j]} where i<j.
      AA,...,ZH includes 208 values, doesn't it? So it seems like your matrix is much bigger than 39 by 39. But I may be misunderstanding something still.
      It is probably possible to do all this in fewer steps, but there probably isn't much change in efficiency.
      (I am getting disconnected a lot, so I may stop posting till later.)
      chas
        there are 39 values (phonemes) between AA and ZH; AA AE AH AO AW AY B CH D DH EH ER EY F G HH IH IY JH K L M N NG OW OY P R S SH T TH UH UW V W Y Z ZH - thanks for the help its great stuff!