MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Question about Tally on a list of lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99299] Re: [mg99267] Question about Tally on a list of lists
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Sat, 2 May 2009 05:58:46 -0400 (EDT)
  • References: <200905010923.FAA01143@smc.vnet.net>

Hi Julian,

Using Tally is probably not a good idea since it is based on SameQ by
default (which is inappropriate for numerical comparison even if you chop
the  numbers) while it will probably be quite slow for large lists if  you
supply your own comparison function based on chopping off extra digits in
your coordinate pairs.

Why not use BinCounts? It is specially designed for this sort of things,
and you can specify the grid in latitude and longitude.

For example, here we generate a small list of random pairs of integers:

In[1] = data = RandomInteger[{1, 100}, {30, 2}]

Out[1] =

{{56, 19}, {88, 4}, {12, 44}, {89, 79}, {2, 44}, {44, 74}, {10,
  14}, {19, 80}, {8, 87}, {56, 32}, {46, 33}, {9, 73}, {20, 52}, {88,
  11}, {30, 35}, {12, 87}, {65, 88}, {24, 57}, {38, 1}, {74, 85}, {29,
   29}, {15, 24}, {75, 62}, {17, 22}, {4, 12}, {5, 37}, {3, 26}, {58,
  24}, {8, 45}, {84, 76}}

Binning them with BinCounts:

In[2] = BinCounts[data, {0, 100, 10}, {0, 100, 20}]

Out[2] = {{1, 2, 2, 1, 1}, {1, 2, 1, 0, 2}, {0, 1, 2, 0, 0}, {1, 1, 0, 0,
  0}, {0, 1, 0, 1, 0}, {1, 2, 0, 0, 0}, {0, 0, 0, 0, 1}, {0, 0, 0, 1,
  1}, {2, 0, 0, 2, 0}, {0, 0, 0, 0, 0}}


Regards,
Leonid



On Fri, May 1, 2009 at 2:23 AM, bleeckerj <bleeckerj at gmail.com> wrote:

> Hi,
>
> So, I'm an on-and-off Mathematica user, just now looking at version 7,
> fussing with a challenge. I have data that represents geo tracks of
> latitude and longitude pairs. I want to turn this array of pairs into
> a heatmap covering the geography of the tracks.
>
> My first thought was to run Tally on the list and get counts for
> latitude/longitude pairs. That was an immediate fail because the pairs
> of data are mostly all different, of course. I thought if I could
> BinList things, piling them into "quadrants" of such-and-so dimensions
> (say, 1 kilometer square, or whatever) I could then count the number
> of bins.
>
> Alternatively, I'd even be happy to somehow reduce the precision of
> the numbers in the list, but after a few hours . I have not been able
> to figure out how to coax Mathematica to somehow truncate the numbers
> down to, say, 4 digits after the decimal point. This would create a
> kind of artificial Bin'ing of the data, which would be fine for my
> purposes. Removing the accuracy would allow me to effectively turn the
> data into a checkerboard of "hits."
>
> But, frankly, I'm not sure how to actually implement any of this,
> either the "truncating" or the Tally technique running over a list of
> lists with a SameQ sort of consideration to allow "close enough" to
> count in a Tally.
>
> I would be grateful for any pointers or suggestions as to how I might
> implement this.
>
> Julian Bleecker
> http://www.nearfuturelaboratory.com
>
>



  • Prev by Date: Re: Re: New Wolfram Tutorial Collection documentation is ready
  • Next by Date: Re: New Wolfram Tutorial Collection documentation is ready
  • Previous by thread: Question about Tally on a list of lists
  • Next by thread: Re: Question about Tally on a list of lists