From: Ivan V. i B. <iv...@ca...> - 2007-12-03 17:56:59
|
David Worrall (el 2007-12-03 a les 00:28:15 +1100) va dir:: > Excellent - thank you both - > I had forgotten the python 'row[:] ' technique since I migrated a few=20 > years ago to using tuple() and list(). > > And the second way is probably faster for computation, no? , - they're= =20 > going in and out of a couple of dicts Well, the implementation of both is little more than one ``.item()`` call away. :) However, I'd be carefull when using NumPy records as dict keys, since they are hashable but also mutable:: In [37]:a =3D numpy.rec.array([(1,'a'), (2,'b')]) In [38]:r =3D a[0] In [39]:rr =3D r.copy() In [40]:d =3D {r: 'x'} In [41]:d Out[41]:{(1, 'a'): 'x'} In [42]:d[r] Out[42]:'x' In [43]:d[rr] -----------------------------------------------------------------------= ---- <type 'exceptions.KeyError'> Traceback (most recent call l= ast) =20 /home/ivan/<ipython console> in <module>() =20 <type 'exceptions.KeyError'>: (1, 'a') In [44]:r['f1'] =3D 'z' In [45]:d Out[45]:{(1, 'z'): 'x'} > Beautiful tool BTW, thanks! Glad to hear that! :) :: Ivan Vilata i Balaguer >qo< http://www.carabos.com/ C=E1rabos Coop. V. V V Enjoy Data "" |