[Numpy-discussion] A bit of advice?

Neal Becker ndbecker2@gmail....
Fri Jun 24 06:29:29 CDT 2011


josef.pktd@gmail.com wrote:

> On Thu, Jun 23, 2011 at 8:20 AM, Neal Becker <ndbecker2@gmail.com> wrote:
>> Olivier Delalleau wrote:
>>
>>> What about :
>>> dict((k, [e for e in arr if (e['x0'], e['x1']) == k]) for k in cases)
>>> ?
>>
>> Not bad!  Thanks!
>>
>> BTW, is there an easier way to get the unique keys, then this:
>>
>> cases = tuple (set (tuple((e['a'],e['b'])) for e in u))
> 
> I think you can just combine these 2
> 
> experiments = defaultdict([])  #syntax ?
> 
> for i, e in enumerate(arr):
>     experiments[tuple((e['a'],e['b']))].append(i)
>     #experiments[tuple((e['a'],e['b']))].append(y['c'])  #or just
> summarize results
> 
> experiments.keys()  #uniques
> 
> (just typed not checked)
> 
> Josef
> 
Yes, thanks, this works quite nicely:
experiments = defaultdict(list)
for e in arr:
     experiments[tuple((e['a'],e['b']))].append(e)




More information about the NumPy-Discussion mailing list