[SciPy-user] How to "move" data within an array
Wed Jul 4 04:23:04 CDT 2007
I'm using numpy arrays for storing data which is generated within an engine.
I'm using the topmost dimension as time axis: every row represents a full
set of data created by the engine while one round.
Say: i have an array for storing prices (e.g. 10 different prices are
generated within one engine round). I'm storing/using the last 5 rounds, so
I get an array with the dimensions (5,10).
If the engine runs longer than 5 rounds I have to "remove" the oldest record
and move the younger records one position back.
Since I've a lot of such arrays I would like to use the most efficient
method avaiable in numpy. On a pure memory-orientated view this would be
just to copy ("move") the memory blocks from the younger 4 rows one row
further, thus having the first row for the new data.
In the C API I see some functions like copyswap() and memmove() which
indicate that such operations are possible at the C API level. But I'm not
sure the correct approach on the Python level.
Taking slices may be one options - but the new slice will then occupy new
memory, causing memory fragmentation...
Looping over all data items, all rows is time consuming and surely wasting
More information about the SciPy-user