1
$\begingroup$

I have a set of numbers that has a non-injective, surjective correspondence to another set of numbers and I would like to quickly create a list of the output. For example, suppose I have 32 54 65 66 71 9 31 34 41 49 18 41 50 68 70 11 50 51 70 75 19 24 26 40 68 17 24 27 48 75 20 21 38 54 66 12 22 46 56 74 14 18 48 54 71 . . . Each of these numbers has a correspondence to another set of numbers. For example each number on the left below corresponds to the number on the right

2 1 4 1 5 2 6 2 7 1 8 1 9 3 10 1 11 3 12 2 13 1 14 3 16 1 17 2 18 3 19 3 20 1 21 2 22 1 24 2 25 1 26 3 27 2 28 4 29 1 30 1 31 2 32 2 33 3 34 3 35 1 36 2 37 2 38 4 40 3 41 3 42 1 44 1 45 2 46 3 48 3 49 2 50 2 51 1 52 2 53 1 54 3 55 1 56 1 57 3 59 2 60 1 62 1 63 1 65 3 66 2 68 3 69 1 70 3 71 3 73 2 74 2 75 2 76 2 77 3

Using this correspondence I now have a list of the form 2 3 3 2 3 3 2 3 3 2 3 3 2 3 3 . . . that is related to the first list.

How can I make this last calculation faster? I have a large number of rows so it isn't practical to look up each corresponding number and write the new set of numbers. I would call these matrices, but the order of numbers in each row does not matter to me. I'm not sure if that matters. So for the first row of the first matrix, 71 exchanged with 32 would not matter to me. Also, for the second list, the numbers on the second column could range from 1,..,n. I have just use n=3 How would I got about make a computation like this?

Any pointers, guidance, suggestions is greatly appreciated.

$\endgroup$
2
  • $\begingroup$ How long is this taking you? I did YourMatrix/.YourRuleSet and it was finished in a fraction of a second. How many hours is that taking with your real problem? Perhaps look at the Dispatch function to speed it up. $\endgroup$
    – Bill
    Jun 11, 2016 at 5:07
  • $\begingroup$ I have very little experience with mathematica. While in principle I know how to compute it by hand, I do not know the code/algorithms in mathematica. So with a large list doing this by hand takes long because I have to look at each number in each row and look up it's corresponding number and then write down each new column. I'm trying my best to learn the language. $\endgroup$ Jun 11, 2016 at 15:14

1 Answer 1

2
$\begingroup$

Try the following code~

asso=Association[Rule@@@list2]
Map[asso,list1,{2}]

will this help?

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.