I am surprised that getting the keys out of a dictionary is faster than getting the first element of an array. Maybe this has to do with the fact that `keys` returns an iterator, whereas you created a new array? If so, you could create an iterator as well.
-erik On Mon, Mar 7, 2016 at 4:50 PM, Christopher Alexander <[email protected]> wrote: > Hello all, I need to create a structure where I keep track of pairs of value > => weight so that I can do various weighted statistical calculations. > > I know that StatsBase has a weights vector, which I plan on using, but the > way that is set up is that it is disassociated from each of the values to > which the weights are to be applied. > > I need the mapping that "Pair" provides, but I've noticed that there is no > easy way, if I have an array of pairs, to grab all the first values or all > the second values (like you can do with a dict in grabbing keys or values). > > I've tried to do something like map(first, my_array_of_pairs), but this is > about 10x slower than if you have a dictionary of value => weight and just > asked for the keys. I actually tried to use a dict at first, but ran into > issues with duplicate values (they were overwriting each other because the > value was the key). > > Any suggestions, or any better way to manipulate an array of Pairs? > > Thanks! > > Chris -- Erik Schnetter <[email protected]> http://www.perimeterinstitute.ca/personal/eschnetter/
