4 ms·
I think that is some kind of feature. Numpy tries hard to guarantee efficient access to its ndarrays and this is simpler to implement using fixed arrays and mos
by zeptomu 9y ago
I think that is some kind of feature. Numpy tries hard to guarantee efficient access to its ndarrays and this is simpler to implement using fixed arrays and mostly you know your bounds at initialization time anyway.
Btw. you can grow them using hstack and vstack although I am not sure how efficient that is.
- xaedes 9y agoGrowing with vstack or hstack is very slow. I have seen code where a big csv with time series data is parsed line by line the corresponding numpy array was grown using vstack for each row. worst case: quadratic runtime
- xapata 9y agoThat'd be so much faster using a generator and a NumPy.concatenate at the end. Orders of magnitude faster, if we're talking about a large CSV.
- dnautics 9y agoThere are fixed arrays in Julia too, for those who absolutely must eke out that last 1% gain in performance
- xapata 9y agoIt ain't just a 1% gain. Use a Python list if you want to append/pop.
- _Wintermute 9y agoA deque is probably a better option for performance.
- xapata 9y agoDepends on how much it grows. I'd actually expect very little difference for most append/pop situations. A deque is there for appendleft and popleft.
- dnautics 9y agothat may be so in Python, but have you checked the performance differences in Julia?