1
$\begingroup$

I'm fairly new to Mathematica, and I've finally stumbled upon something that's beyond my googling powers.

I have a list of pairs, where each pair contains in its first entry a matrix and in its second some information about how it was generated. It looks like this:

Mathematica output of list

You can review the full list using:

list=Uncompress@"1:eJy9nU1y3DYQhTljKvfIAVIlS6dwVVY+Qhau8ioL52C5oJ1YHFlNQt0A+3uY9sIui+\
Y8o8n3A6CH/P2vvz9/+feyLN/WZVn+/Prtny/X5eTfPv08bfm4/f7oHHm8Hf+y7o98/\
fnnsvvt5Z+cR9z+uXPO7rMitODMk+N7AuO7QsTHTy8/++Oj+595PeRgXmhNt3P++/nLq/\
US1PSyCDXtjjAs6oUW9Qb2+sHhoUcP80qL+lLPW/Gcn2/FjtBIUV+H4VZ1f+wpRKU3K6L/\
B1pVRP8Pyq2K6P9BqSik/0prup2Tpf+q1JTRf6VFFej/QIuK6P9AiyrR/\
0G7WZNlNZfC96rD/6isR0+\
cPkC3qIbJNTXkhy86ZsakqEb0c6J6tH4uqmR8Iv89nwpE1eBITe2GPCeqx8Ep/\
PesyldVw6xlP3b/4Jw++yX3h+yX/J+xH9s/Yr9k/4j9M9w/y37N/bPsn+L+\
SfZj7x9U9dGvqsnpzKpun+XQ/yjes6s6HOLdRNWFxO4fnLNLsBHa/\
UQ1HuEdRNV3KvNFUtRIVK1kEdp8Uf01g40Qi+mP3R/RH7u/Qn9x+k/oj+0/OKdPf8n+\
If1xAOD0x/6P6I/9H9NfnPknS2rEx/dpFKmckh5l5i4DbGtqkKKk+\
tHYpYbpGylqtEplxY7QVElFQ+Ts94yqI6km4KSqQW1CST3aBR9ga1M9STXMWv5rc/8s/\
8W5P+E/9n6B/9j8Ef+x+Sv8F92f8F9z/yz/J7h/mv+S/4v7/leKeH7dyMAuEiLe+\
88h9iUu2jO6LKyitxN/EDRQzVs9vhM0UEllx89cn2A+cUxyj24f/MwxSW0x94/xuIL7x+\
RYwf1jrJoZOFwV3zDN/dEob/ctwaSVfXq9bwlmsRpYBqhTA0sCdWpgSQD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dMDKQyIjQO/\
UUTcOIARceMAQJQfJ4BGuX1wdvPQUgHAhJuHlg2SmB2hPeihg2nhgGCqrQQEU20lwEzBrQ\
RVamDZoEoNLBrUqYFFgzo1sGhQpwaWDOrUwKJBnRpYNqhTA8sGOUz2deMFVlV9mEASTXyY\
QBLt7Wzv55cAjSYBs5w0Gqnkmyym0UglxYcJEDT+\
KgGC5rRkjtHK2E19Xn2YQAW7qb8zdlNnZ+ymns7YTd1cfZhABbupgzN2U+\
9Wtv0WWE9p22+BZZW2/RZaXbQ4ZL4gFDe5OGSYuLZs2w9P7w8zBe+Ql3PNBElpd/\
MW3AgAINVGgDpFwLN7RRHwBF9RBHGOTxSBBgFFEWgcUBSBhgJBEfAMnysCnuBzRcAZYbgu\
5UE2jQAV17JpBKi4lk0jwDypPSqiA6oFhGCg51CFdSlXbM+\
hcknw1Havww6ilBGyq8ZNdwBGxG8WKNMDcfkfQ9bqAQ4Hih5o8YDqgRYQqB6IEQHogZQQk\
B5IAQHpwTEf/A8UxMr9";

So for example, the first pair is {{{1,0},{0,1}},{0,0,0,1}}, the identity matrix with some info. Now I want to delete pairs where the first element, the matrix, is duplicated. I have Mathematica 10, and thought of using DeleteDuplicatesBy and First, as in the example given in the description of DeleteDuplicatesBy, but was unsure exactly how (typing DeleteDuplicatesBy[list,First] doesn't run). Could anybody correct me please?

Also, Mathematica kindly suggested to me that using First/@list would give me all the matrices (as opposed to First[list] which gives me the first pair). I don't exactly know how this syntax works either, so if somebody could explain that too it would be great.

$\endgroup$
  • $\begingroup$ DeleteDuplicatesBy[elms, First] (elms is my simple list of pairs)... and it works. What you mean by "doesn't run"? $\endgroup$ – m0nhawk Mar 30 '15 at 10:05
  • $\begingroup$ @m0nhawk If I run DeleteDuplicatesBy[elms, First] I just get back (as output) DeleteDuplicatesBy[{{{{1, 0}, {0, 1}}, {0, 0, 0, 1}}, {{{1, 1}, {0, 1}}, {0, 0, 1, 1}}, {{{1, 2}, {0, 1}}, {0, 0, 2, 1}}, {{{0, -1}, {1, -1}}, {0, 1, 0, 1}}, ..., {3, 5, 2, 6}}}, First] $\endgroup$ – Shakespeare Mar 30 '15 at 10:08
  • $\begingroup$ Please post data/code as text, not (only) as images. $\endgroup$ – Yves Klett Mar 30 '15 at 10:11
  • $\begingroup$ @YvesKlett Is there a way to spoiler it? There's quite a bit... $\endgroup$ – Shakespeare Mar 30 '15 at 10:14
  • $\begingroup$ @user3006690: Use Compress on your data and post the full result. It should be much shorter. Place a hint to use Uncompress on it in your question, also. $\endgroup$ – Jinxed Mar 30 '15 at 10:17
4
$\begingroup$

Using the compressed list you supplied:

list=Uncompress@"<...>";

Length@list
(* 432 *)

Length@(dedup = DeleteDuplicatesBy[list, First])
(* 54 *)

Here is the result:

dedup=Uncompress@"1:eJytmEFuwzAMBGXZ6D/6ib6ipz6hBwM59ZB+\
324dHUTY3qWsNQPEaBQoI66WpNT375+v+SOl9Jy2x+fj+Tvnq58ew/bHY3unw/hrqHw5T+\
dxewynmW3aec4FGpnZpmWFlgVamfi3vdAqyjigVflDaYnENiRRSZfGlKzy99JeIOSSMs5i\
y6qS9qtgnO1bDUuiASXL+\
OrRZE92KGl2lD3JaEDJvflDaUBJoylKWhZfqyWWapGeZLXEUk2mddSSfWJLtPV6LTGaXEu\
AkokoaSJGKtmmRSrZpoXXErBvZhBFSZZvzJNmEJkGXMI8ubdj1CnIziuMFn4uAbTxlktY7\
2aeHO+7BOwb8+\
R43yUd3dRokadX1k2NJvc3VpXd0ytZp0srK1wUWhZoq3yeVGJbZJoSG6uThQaye38FiKIV\
hUePpsTGencmLjmcS4JoY5Mmx8ay2+2mSmy2P700JTbbn97ercQ2yjR531jvBrcO62+\
yJwHN6iejybUEZMBKXHLob0G0pUmTYwP5VsbbleucO+19A/0tVa+\
6tUShgd5tq3Bd0kkb8Bx6Ez7sm0ID2d3uAeUxCUqCfGtngEKrqXPx1nHo3W99tLrWbloWa\
Kv3fy73HqDEtngZ4NJqbP8TQbe7";

If you do not get the same result, please restart Mathematica first to get rid of any previous defines you may have made in your session.

Regarding /@: Please review the documentation on Map.

$\endgroup$

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.