replacing numbers in LARGE MATRIX with criterium in 2 columns (a-->b)

A

Alexzive

Hello,
I have this matrix [20*4 - but it could be n*4 , with n~100,000] in
file "EL_list" like this:

1, 1, 2, 3
2, 4, 1, 5
3, 5, 1, 6
4, 7, 5, 6
5, 8, 7, 9
6, 8, 5, 7
7, 10, 9, 7
8, 10, 11, 12
9, 7, 13, 10
10, 14, 15, 16
11, 14, 17, 15
12, 17, 14, 18
13, 13, 16, 10
14, 16, 15, 11
15, 16, 11, 10
16, 19, 20, 21
17, 22, 15, 20
18, 17, 20, 15
19, 23, 20, 24
20, 25, 24, 20

I would like to replace some numbers in "EL_list" but only in columns
2,3,4 using the criterium by line in file "criterium" (column 1 are
the new numbers, column 2 the old ones).

1 1
2 3
3 5
4 12
5 13
6 14
7 15
8 16
9 17
10 18
11 19
12 10
13 21
14 22
15 23
16 24
17 25

For example all the 7 have to replaced by 15 and so on..

-- How to implement it in a fast end efficient code?

many thanks, Alex
 
A

Alessandro

Hello,
I have this matrix [20*4 - but it could be n*4 , with n~100,000] in
file "EL_list" like this:

1, 1, 2, 3
2, 4, 1, 5
3, 5, 1, 6
4, 7, 5, 6
5, 8, 7, 9
6, 8, 5, 7
7, 10, 9, 7
8, 10, 11, 12
9, 7, 13, 10
10, 14, 15, 16
11, 14, 17, 15
12, 17, 14, 18
13, 13, 16, 10
14, 16, 15, 11
15, 16, 11, 10
16, 19, 20, 21
17, 22, 15, 20
18, 17, 20, 15
19, 23, 20, 24
20, 25, 24, 20

I would like to replace some numbers in "EL_list" but only in columns
2,3,4 using the criterium by line in file "criterium" (column 1 are
the new numbers, column 2 the old ones).

1 1
2 3
3 5
4 12
5 13
6 14
7 15
8 16
9 17
10 18
11 19
12 10
13 21
14 22
15 23
16 24
17 25



For example all the 7 have to replaced by 15 and so on..

ERRATA: for example, all the 15 have to replaced by 7 and so on..
 
D

Dave Angel

Alessandro said:
Hello,
I have this matrix [20*4 - but it could be n*4 , with n~100,000] in
file "EL_list" like this:

1, 1, 2, 3
2, 4, 1, 5
3, 5, 1, 6
4, 7, 5, 6
5, 8, 7, 9
6, 8, 5, 7
7, 10, 9, 7
8, 10, 11, 12
9, 7, 13, 10
10, 14, 15, 16
11, 14, 17, 15
12, 17, 14, 18
13, 13, 16, 10
14, 16, 15, 11
15, 16, 11, 10
16, 19, 20, 21
17, 22, 15, 20
18, 17, 20, 15
19, 23, 20, 24
20, 25, 24, 20

I would like to replace some numbers in "EL_list" but only in columns
2,3,4 using the criterium by line in file "criterium" (column 1 are
the new numbers, column 2 the old ones).

1 1
2 3
3 5
4 12
5 13
6 14
7 15
8 16
9 17
10 18
11 19
12 10
13 21
14 22
15 23
16 24
17 25




For example all the 7 have to replaced by 15 and so on..

ERRATA: for example, all the 15 have to replaced by 7 and so on..
What have you come up with so far? Did the instructor give you any
sample code to solve similar problems? Did he really describe it as a
matrix?

Sounds to me like you have two text files. One contains a replacement
table (which you can read into a dictionary), and the other (large) file
is just text. After building the dictionary, you'd want a loop that
goes through the text file, splitting each line into a list of four.
You then use the dictionary to replace list items 1, 2, and 3, and write
the result someplace.

Try writing the code, see if anything goes wrong, and then ask for help.
 
M

MRAB

Alexzive said:
Hello,
I have this matrix [20*4 - but it could be n*4 , with n~100,000] in
file "EL_list" like this:

1, 1, 2, 3
2, 4, 1, 5
3, 5, 1, 6
4, 7, 5, 6
5, 8, 7, 9
6, 8, 5, 7
7, 10, 9, 7
8, 10, 11, 12
9, 7, 13, 10
10, 14, 15, 16
11, 14, 17, 15
12, 17, 14, 18
13, 13, 16, 10
14, 16, 15, 11
15, 16, 11, 10
16, 19, 20, 21
17, 22, 15, 20
18, 17, 20, 15
19, 23, 20, 24
20, 25, 24, 20

I would like to replace some numbers in "EL_list" but only in columns
2,3,4 using the criterium by line in file "criterium" (column 1 are
the new numbers, column 2 the old ones).

1 1
2 3
3 5
4 12
5 13
6 14
7 15
8 16
9 17
10 18
11 19
12 10
13 21
14 22
15 23
16 24
17 25

For example all the 7 have to replaced by 15 and so on..

-- How to implement it in a fast end efficient code?
>
Read the contents of "criterium" into a dict with the old value as the
key and the new value as the value and then iterate through the matrix
replacing the values in columns 2 to 4 with criterium.get(current_value,
current_value).

Incidentally, the singular of "criteria" is "criterion" because it's
Greek, not Latin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top