[Numpy-discussion] A bit of advice?

josef.pktd@gmai... josef.pktd@gmai...
Thu Jun 23 08:03:46 CDT 2011


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

>
>>
>> (note: it is inefficient written this way though)
>>
>> -=- Olivier
>>
>> 2011/6/23 Neal Becker <ndbecker2@gmail.com>
>>
>>> I have a set of experiments that I want to plot.  There will be many plots.
>>> Each will show different test conditions.
>>>
>>> Suppose I put each of the test conditions and results into a recarray.  The
>>> recarray could be:
>>>
>>> arr = np.empty ((#experiments,), dtype=[('x0',int), ('x1',int), ('y0',int)]
>>>
>>> where x0,x1 are 2 test conditions, and y0 is a result.
>>>
>>> First I want to group the plots such according to the test conditions.  So,
>>> I
>>> want to first find what all the combinations of test conditions are.
>>>
>>> Dunno if there is anything simpler than:
>>>
>>> cases = tuple (set ((e['x0'], e['x1'])) for e in arr)
>>>
>>> Next, need to select all those experiments which match each of these cases.
>>>  Now
>>> I know of no easy way.
>>>
>>> Any suggestions?  Perhaps I should look again at pytables?
>>>
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list