Sponsored Content
Full Discussion: Randomize a matrix
Top Forums Shell Programming and Scripting Randomize a matrix Post 302743573 by @man on Thursday 13th of December 2012 03:23:57 AM
Old 12-13-2012
Help with Perl

You are damn right Jim! Smilie I like how you described it... cool!! Smilie
I found an algorithm how to randomize my -rather complex to explain- data.

I explain it here:

Suppose I have the following input file:

Code:
*	A	B	C	D	E
reg1	1	0	1	1	0
reg2	0	1	0	0	1
reg3	1	0	0	1	0
reg4	0	0	1	0	1
reg5	1	1	0	0	1

First of all I would like to store it in a hash or 2 dimensional array which is like this:

Code:
A	rand#
A	rand#
A	rand#
B	rand#
B	rand#
C	rand#
C	rand#
D	rand#
D	rand#
E	rand#
E	rand#
E	rand#

As you can see the first column represents as many as headers that we had value '1' for them in input file. Second column is just a random number between 0-1.

Then we initiate an empty matrix with the same size as input file and start filling it with respect to previous table contained headers and random numbers.

The script should first sort the above table by the numbers (2nd column). therefore in each iteration we gonna have random order for headers in first column. Additionally, for each header a value '1' should be located in the corresponding column in our empty table.

to make sure that we don't make a mistake, each time that we take a header a value of 1 should be added to that row (in an additional third column). next time when we want to pick another header, we check the value in third column. If it was 1 we skip it since we know that it has been taken.
This goes repeatedly until the sum of the first row in our recently empty table turns equal to sum of the first row in input file. Then it goes to the second row and continue filling the rows until we have used all the headers.

if this can be solved then I can move on.

Thanks.
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

diagonal matrix to square matrix

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

2. Shell Programming and Scripting

Matrix

Hi All I would like to merge multiple files with the same row and column size into a matrix format In a folder I have multiple files in the following format vi 12.txt a 1 b 5 c 7 d 0 vi 45.txt a 3 b 6 c 9 d 2 vi 9.txt a 4 (7 Replies)
Discussion started by: Lucky Ali
7 Replies

3. 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

4. Programming

Matrix code in C++

I have the code below in C++ and am trying to understand what these do and how to call them. template <class Type> class Matrix { public: Matrix(); Matrix( const int m, const int n ); Matrix( const Matrix& A ); ~Matrix(); (0 Replies)
Discussion started by: kristinu
0 Replies

5. Shell Programming and Scripting

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... (5 Replies)
Discussion started by: stonemonkey
5 Replies

6. Shell Programming and Scripting

Randomize letters

Hi, Is there a tool somewhat parallel to rev, but which randomizes instead of reverses? I've tried rl, but I can only get it to randomize words. I was hoping for something like this echo "hello" | ran leolh less simpler solutions are also welcome. Sorry if the question is... (21 Replies)
Discussion started by: jeppe83
21 Replies

7. Shell Programming and Scripting

Randomize a file

Hi, I have a large file that looks like this: @FCC189PACXX:2:1101:1420:2139/1 AGCGAGACTCCGTCTCAAAAAGAAAAAATTTTTCAAAATATTGCAATGGGCTTGTAATTTCTGCTTAAATGTCAGGAGGTCTGAGCCATT + bbbeeeceggggghiiiiiiiiiihfihihiiihhhghiihhihifhihiihhhhhhhhiiigfggggdceeeeebdcc^``bbcbccbb... (3 Replies)
Discussion started by: kylle345
3 Replies

8. Shell Programming and Scripting

Randomize columns in CSV file

Hi there, friends! Writing exams again! This time my wish would be to randomize certain columns in a csv file. Given a file containing records consisting of 3 columns tab-separated: A B C A B C A B C I would love to get the columns of each record in random order...separated by a tab as... (12 Replies)
Discussion started by: eldeingles
12 Replies
zlacrm.f(3)							      LAPACK							       zlacrm.f(3)

NAME
zlacrm.f - SYNOPSIS
Functions/Subroutines subroutine zlacrm (M, N, A, LDA, B, LDB, C, LDC, RWORK) ZLACRM multiplies a complex matrix by a square real matrix. Function/Subroutine Documentation subroutine zlacrm (integerM, integerN, complex*16, dimension( lda, * )A, integerLDA, double precision, dimension( ldb, * )B, integerLDB, complex*16, dimension( ldc, * )C, integerLDC, double precision, dimension( * )RWORK) ZLACRM multiplies a complex matrix by a square real matrix. Purpose: ZLACRM performs a very simple matrix-matrix multiplication: C := A * B, where A is M by N and complex; B is N by N and real; C is M by N and complex. Parameters: M M is INTEGER The number of rows of the matrix A and of the matrix C. M >= 0. N N is INTEGER The number of columns and rows of the matrix B and the number of columns of the matrix C. N >= 0. A A is COMPLEX*16 array, dimension (LDA, N) A contains the M by N matrix A. LDA LDA is INTEGER The leading dimension of the array A. LDA >=max(1,M). B B is DOUBLE PRECISION array, dimension (LDB, N) B contains the N by N matrix B. LDB LDB is INTEGER The leading dimension of the array B. LDB >=max(1,N). C C is COMPLEX*16 array, dimension (LDC, N) C contains the M by N matrix C. LDC LDC is INTEGER The leading dimension of the array C. LDC >=max(1,N). RWORK RWORK is DOUBLE PRECISION array, dimension (2*M*N) Author: Univ. of Tennessee Univ. of California Berkeley Univ. of Colorado Denver NAG Ltd. Date: September 2012 Definition at line 115 of file zlacrm.f. Author Generated automatically by Doxygen for LAPACK from the source code. Version 3.4.2 Tue Sep 25 2012 zlacrm.f(3)
All times are GMT -4. The time now is 07:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy