TransWikia.com

Fast way to count distinct pairs of integers

Mathematica Asked on April 8, 2021

I have a association list, S, whose size is about 5*10^4. I also have a function F which takes in ordered pairs of elements from S, and spits out ordered pairs of integers. There is some amount of repetition among these outputs of F.

I’d like to compute the exact cardinality of the image of F, if that’s possible.


Edited to add: By modifying the function F, we might as well assume that S is just Range[1,2.5*10^9], and that F outputs a single 20 digit integer for each input. Computing F[S] is highly memory intensive. I was thinking that perhaps one way to handle this would be to print the outputs, according to their modulus, mod 1000, to different files, and then compute the number of distinct outputs in each file, separately. Are there fast ways to do that?

One Answer

You can use CountDistinctBy:

CountDistinctBy[F][S]

Answered by kglr on April 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP