8 Sep
2011
8 Sep
'11
7:43 a.m.
Wed, 07 Sep 2011 12:52:44 -0700, Chris.Barker wrote: [clip]
In [9]: temp['x'] = 3
In [10]: temp['y'] = 4
In [11]: temp['z'] = 5 [clip] maybe it wouldn't be any faster, but with re-using temp, and one less list-tuple conversion, and fewer python type to numpy type conversions, maybe it would.
Structured array assignments have plenty of overhead in Numpy, so it could be slower, too: x = np.array((1,2), dtype=[('a', int), ('b', float)]) x2 = [1,2,3] %timeit x['a'] = 9 100000 loops, best of 3: 2.83 us per loop %timeit x2[0] = 9 1000000 loops, best of 3: 368 ns per loop