10-01-2011
awk? adjacency matrix to adjacency list / correlation matrix to list
Hi everyone
I am very new at awk but think that that might be the best strategy for this. I have a matrix very similar to a correlation matrix and in practical terms I need to convert it into a list containing the values from the matrix (one value per line) with the first field of the line (row annotation) && the header of the field (column annotation) and some spaces etc. preceding it.
In more abstract terms, I wish to convert an adjacency matrix into adjacency list, which includes the edge weights. In excel it works fine with =IF(B2>0;$A2&" (gg) "&B$1&" = "&B2;"") and some grep but the datasets became just to big. P.S 0 values should be omitted.
Input
| AA | AB | AC | ... | ZZ |
AA | 1 | 0 | 0.5 | 0 | 0.7 |
AB | 0 | 1 | 0.3 | 0 | 0 |
AC | 0 | 0 | 1 | 0 | 0.1 |
... | 0 | 0 | 0 | 1 | 0 |
ZZ | 0 | 0 | 0 | 0 | 1 |
Output
AA (gg) AA = 1
AA (gg) AC = 0.5
AA (gg) ZZ = 0.7
AB (gg) AB = 1
AB (gg) AC = 0.3
AC (gg) AC = 1
AC (gg) ZZ = 0.1
... (gg) ... = 1
ZZ (gg) ZZ = 1
Thanks a million for your efforts☺.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I have few days to complete my awk homework. But I'm stucked. i hope some1 will help me out.
I have to inverse n x n matrix, but I have problems with finding the determinant of the matrix.
I found the algoritm, how to find a determinant of n x n matrix:... (0 Replies)
Discussion started by: vesyyr
0 Replies
2. Programming
Hi power user,
I have this type of data (distance list):
file1
A B 10
B C 20
C D 50I want output like this
# A B C D
A 0 10 30 80
B 10 0 20 70
C 30 20 0 50
D 80 70 50 0 Which is a distance matrix
I have tried... (0 Replies)
Discussion started by: anjas
0 Replies
3. Shell Programming and Scripting
hi there
I'm very new in programing and i've started with awk.
I'm processing 200 data files and I need to do some precessing on them.
The files have 3 columns with N-lines
for each line a have on the first and second value is the same for all the files and only the third is variable. like... (2 Replies)
Discussion started by: philstar
2 Replies
4. Shell Programming and Scripting
Hello, all!
I am struggling with a short script to read a diagonal matrix for later retrieval.
1.000 0.234 0.435 0.123 0.012 0.102 0.325 0.412 0.087 0.098
1.000 0.111 0.412 0.115 0.058 0.091 0.190 0.045 0.058
1.000 0.205 0.542 0.335 0.054 0.117 0.203 0.125
1.000 0.587 0.159 0.357... (11 Replies)
Discussion started by: yifangt
11 Replies
5. Ubuntu
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
6. Shell Programming and Scripting
Hi there,
If anyone can help me sorting out this small task would be great. Given a matrix like the following:
100 3 3 3 3 3 ...
200 5 5 5 5 5 ...
400 1 1 1 1 1 ...
500 8 8 8 8 8 ...
900 0 0 0 0... (5 Replies)
Discussion started by: JRodrigoF
5 Replies
7. Shell Programming and Scripting
Greetings, salutations.
I have a 3 column csv file with ~13 million rows and I would like to generate a correlation matrix. Interestingly, you all previously provided a solution to the inverse of this problem. Thread title: "awk? adjacency matrix to adjacency list / correlation matrix to list"... (6 Replies)
Discussion started by: R3353
6 Replies
8. Shell Programming and Scripting
dear awk gurus,
i would need a fast (therefore) awk solution for the reformation of an uncomplete weighted adjacency list to a complete sorted adjacency matrix.
example (FS=OFS=,):
a,d,0.33
a,b,0.25
b,c,0.11
should give:
,a,b,c,d
a,1,0.25,0,0.33
b,0.25,1,0.11,0... (4 Replies)
Discussion started by: dietmar13
4 Replies
9. UNIX for Dummies Questions & Answers
I want to go from
1,a,1a
1,b,1b
1,c,1c
2,a,2a
2,b,2b
3,a,3a
to
a,b,c
1,1a,1b,1c
2,2a,2b,-
3,3a,-,-
Here is what I tried
awk -F, 'BEGIN {OFS = ","} (4 Replies)
Discussion started by: senhia83
4 Replies
10. Shell Programming and Scripting
input
A1 B1 A2 B2
0 0 1 1
1 0 0 1
0 1 1 0
1 1 1 1
Output
label A1 B1 A2 B2
A1 2 1 1 2
B1 1 2 2 1
A2 1 2 3 2
B2 2 1 2 3
Ex:
The number of times that A1 and B1 row values are both 1 should be printed as output.
The last row of A1 and B1 in the input match by having 1 in both... (4 Replies)
Discussion started by: quincyjones
4 Replies
LEARN ABOUT REDHAT
glmultmatrixf
GLMULTMATRIX(3G) GLMULTMATRIX(3G)
NAME
glMultMatrixd, glMultMatrixf - multiply the current matrix with the specified matrix
C SPECIFICATION
void glMultMatrixd( const GLdouble *m )
void glMultMatrixf( const GLfloat *m )
PARAMETERS
m Points to 16 consecutive values that are used as the elements of a 4x4 column-major matrix.
DESCRIPTION
glMultMatrix multiplies the current matrix with the one specified using m, and replaces the current matrix with the product.
The current matrix is determined by the current matrix mode (see glMatrixMode). It is either the projection matrix, modelview matrix, or
the texture matrix.
EXAMPLES
If the current matrix is C, and the coordinates to be transformed are, v=(v[0],v[1],v[2],v[3]). Then the current transformation is Cxv, or
c[0] c[4] c[8] c[12] v[0]
(c[1] c[5] c[9] c[13])x(v[1])
c[2] c[6] c[10] c[14] v[2]
c[3] c[7] c[11] c[15] v[3]
Calling glMultMatrix with an argument of m=m[0],m[1],...,m[15] replaces the current transformation with (CxM)xv, or
c[0] c[4] c[8] c[12] m[0] m[4] m[8] m[12] v[0]
(c[1] c[5] c[9] c[13])x(m[1] m[5] m[9] m[13])x(v[1])
c[2] c[6] c[10] c[14] m[2] m[6] m[10] m[14] v[2]
c[3] c[7] c[11] c[15] m[3] m[7] m[11] m[15] v[3]
Where 'x' denotes matrix multiplication, and v is represented as a 4x1 matrix.
NOTES
While the elements of the matrix may be specified with single or double precision, the GL may store or operate on these values in less than
single precision.
In many computer languages 4x4 arrays are represented in row-major order. The transformations just described represent these matrices in
column-major order. The order of the multiplication is important. For example, if the current transformation is a rotation, and
glMultMatrix is called with a translation matrix, the translation is done directly on the coordinates to be transformed, while the rotation
is done on the results of that translation.
ERRORS
GL_INVALID_OPERATION is generated if glMultMatrix is executed between the execution of glBegin and the corresponding execution of glEnd.
ASSOCIATED GETS
glGet with argument GL_MATRIX_MODE
glGet with argument GL_COLOR_MATRIX
glGet with argument GL_MODELVIEW_MATRIX
glGet with argument GL_PROJECTION_MATRIX
glGet with argument GL_TEXTURE_MATRIX
SEE ALSO
glLoadIdentity(3G), glLoadMatrix(3G), glMatrixMode(3G), glPushMatrix(3G)
GLMULTMATRIX(3G)