fasoli has asked for the wisdom of the Perl Monks concerning the following question:
I am looking to find a way to convert a 2 column / 100,000 line file into a matrix. In this file, the columns represent X and Y values.
What I want to get is the following matrix, like so:
If I have x coordinates x1, x2, x3 and y coordinates y1, y2, y3, I want to get all possible combinations, like x1,y1, x1,y2, x1,y3, x2,y1, x2,y2, x2,y3, x3,y1,vx3,y2, x3,y3 - in the form of a matrix but I can't format it properly for this post :'(
I also want to get a population, which would be a count of how many times the coordinate (for example) (56,6 , 85,5) occurs and divide this by 100,000.
A few questions as I don't know how to begin:
1. the coordinates have 10 decimal points and I'd like to maybe round them up at 2, is there a way to do that before calculating the matrix?
2. is there a Perl module specifically for matrices? Does this http://docstore.mik.ua/orelly/perl/advprog/ch02_02.htm seem like a link that would help me? Also I tried some things from here https://www.biostars.org/p/60546/, specifically I tried this one-liner
perl -lane '$cnt{$_}++; END { foreach $key (keys %cnt) {print "$key\t$cnt{$key}"} }' input.txtdo you think it could be doing what I want? I know it's not giving me any population details but I'm not even sure if this code is for combining all coordinates?
IThe reason why I need this is to be able to plot a heat map later on with gnuplot.
Also another question for a potential gnuplot/Perl specialist here, is there a way for gnuplot to maybe "interpret" or count the occurrences on its own, without me having a population column or something like that in the file? Maybe if the input coordinates are already in the form of a matrix, gnuplot is able to count them and push this result into a heat map, representing the fractional population of the data?
I have a feeling that it might be a matter of "simply" having loops going through all entries or something like that? I would appreciate any hints/information as I don't know how to begin, I don't expect you to try and write the code for me but some guidance would be more than welcome.
Thank you all very much in advance, any information would be greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: convert columns into matrix and get population count?
by Athanasius (Cardinal) on May 20, 2016 at 16:05 UTC | |
by fasoli (Beadle) on May 24, 2016 at 17:05 UTC | |
by Athanasius (Cardinal) on May 25, 2016 at 04:19 UTC | |
by fasoli (Beadle) on May 26, 2016 at 14:31 UTC | |
by Athanasius (Cardinal) on May 27, 2016 at 09:35 UTC | |
by Discipulus (Canon) on May 27, 2016 at 09:57 UTC | |
|
Re: convert columns into matrix and get population count?
by BrowserUk (Patriarch) on May 20, 2016 at 16:19 UTC |