Invert Matrix of Data - Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Invert Matrix of Data - Perl
# 1  
Old 04-12-2010
Invert Matrix of Data - Perl

I have columnar data in arrays perl, Example -

Code:
@a = (1,2,3);
@array1 = (A,B,C);
@array2 = (D,E,F);
@array3 = (I,R,T);

I want the data to be formatted and printed as

Code:
1 A D I
2 B E F
3 C F T

and so on...
# 2  
Old 04-12-2010
do you want this?
Code:
#!/usr/bin/perl
 
@a = (1,2,3);
@a1 = (A,B,C);
@a2 = (D,E,F);
@a3 = (I,R,T);
 
for($i=0;$i<= $#a;$i++ ) {
 
print "$a[$i] $a1[$i] $a2[$i] $a3[$i]\n";
}

# 3  
Old 04-12-2010
I think i have not explained well here.

I have a array which has number of columns which would exists say 15 and another array which stores data in this format
Code:
$arraywhichhascount[$index] = 15;

This arrayRef has values stores in columnar format so for example

Code:
$arraywhichhasdata[1] = \@arrayRef;
$arraywhichhasdata[2] = \@arrayRef;

would store all values for column 1 in similar manner all column values are being stored I need to get this columnar data in row form.

What i tried
Code:
for (my $i=1;$i<scalar($arraywhichhascount) ;$i++) 
{
	foreach my $colData (@arraywhichhasdata)
	{
		print @{$colData};

	}
}

I know i'm doing it wrong.


I also tried something like this

Code:
for (my $i=1;$i<($rowcount+1) ;$i++)
{
	foreach my $colData (@columnValues)
	{
		if (defined $columnValues[$i])
		{
			print "$i == @{columnValues}\n";
		}
		else
		{
			print "$i==$columnValues[$i]\n";
		}
	}
}

# 4  
Old 04-12-2010
use below:-

Code:
perl -le '
@a = (1,2,3);
@array1 = (A,B,C);
@array2 = (D,E,F);
@array3 = (I,R,T);
@b=(\@a, \@array1, \@array2, \@array3) ;
push @total , [ @{$_}  ] for @b  ;
for ($i=0;$i<=@b;$i++) {
          for ($j=0;$j<=@a;$j++) {
                    printf "$total[$j][$i] " ;
                                    }
         print "" ;
               }
'

SmilieSmilieSmilie
# 5  
Old 04-12-2010
No this does not help
# 6  
Old 04-12-2010
Quote:
Originally Posted by dinjo_jo
No this does not help
why ?
Code:
the o/p:-
1 A D I 
2 B E R 
3 C F T

so what is the problem?!?!?!
# 7  
Old 04-12-2010
see my 3rd post
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert data into tabular matrix

Hi There, I want to convert the following data into tabular matrix, based on column 4th and 5th, and output the column 10th value chr1 2804449 2804450 NACpG_1 window1 + chr1 2804443 2804475 1 chr1 2804450 2804451 NACpG_1 window2 + chr1 2804443 ... (3 Replies)
Discussion started by: ChiragNepal
3 Replies

2. Shell Programming and Scripting

How order a data matrix using awk?

is it possible to order the following row clusters from ascending to descending. thanx in advance input 1 2 4 0 1 2 4 0 3 3 3 3 1 5 1 0 1 5 1 0 6 0 0 0 5 1 1 1... (4 Replies)
Discussion started by: quincyjones
4 Replies

3. Shell Programming and Scripting

[Solved] Converting the data into matrix with 0's and 1's

I have a file that contains 2 columns tag,pos cat input_file tag pos atg 10 ata 16 agt 15 agg 19 atg 17 agg 14 I have used following command to sort the file based on second column sort -k 2 input_file tag pos atg 10 agg 14 agt 15 ata 16 agg 19 atg 17 (2 Replies)
Discussion started by: raj_k
2 Replies

4. Shell Programming and Scripting

Reformatting data in matrix form

Hi, Some assistance with respect to the following problem will be very helpful. I want to reformat my dataset in the following manner for subsequent analysis. I have first column values (which repeat for each value of 2nd column) which are names, the second column specifies position ad the... (1 Reply)
Discussion started by: newbie83
1 Replies

5. Shell Programming and Scripting

convert data into matrix- awk

is it possible to count the number of keys based on state and cell and output it as a simple matrix. Ex: cell1-state1 has 2 keys cell3-state1 has 4 keys. Note: Insert 0 if no data available. input key states cell key1 state1 cell1 key1 state2 cell1 key1 ... (21 Replies)
Discussion started by: quincyjones
21 Replies

6. Ubuntu

How to convert full data matrix to linearised left data matrix?

Hi all, Is there a way to convert full data matrix to linearised left data matrix? e.g full data matrix Bh1 Bh2 Bh3 Bh4 Bh5 Bh6 Bh7 Bh1 0 0.241058 0.236129 0.244397 0.237479 0.240767 0.245245 Bh2 0.241058 0 0.240594 0.241931 0.241975 ... (8 Replies)
Discussion started by: evoll
8 Replies

7. Shell Programming and Scripting

two-column data to matrix in AWK

Howdy, I need to convert an association data matrix, currently in a two-column format, into a matrix with numbers indicating the number of associations. I've been looking around for AWK code in the list, but could not find anything. Here's an example of what I want to perform: original... (10 Replies)
Discussion started by: sramirez
10 Replies

8. Shell Programming and Scripting

extract data from a data matrix with filter criteria

Here is what old matrix look like, IDs X1 X2 Y1 Y2 10914061 -0.364613333 -0.362922333 0.001691 -0.450094667 10855062 0.845956333 0.860396667 0.014440333 1.483899333... (7 Replies)
Discussion started by: ssshen
7 Replies

9. Shell Programming and Scripting

Merge 70 files into one data matrix

Hi, I have a list of 70 files in a directory and I need to merge the content of each file into one big matrix file (71 columns x 3060 rows). Each file has the following format only two columns per file: unique identifier1 randomtext1 randomtext1 a 5 b 3 c 6 d 3 e 2... (11 Replies)
Discussion started by: labrazil
11 Replies

10. UNIX for Dummies Questions & Answers

changing data into matrix form

Hi, I have a file whose structure is like this 7 7 1 2 3 4 5 1 3 4 8 6 1 4 5 6 0 2 6 8 3 8 2 5 7 8 0 5 7 9 4 1 3 8 0 2 2 3 5 6 8 basically first two row tell the number of rows and column but the data following them are not arranged in that format. now i want to create another... (1 Reply)
Discussion started by: g0600014
1 Replies
Login or Register to Ask a Question