For image processing, I need an array (array type, not numpy array) for 2 million 32 bit words. If I use something like:
tb = array.array( 'i', ,(0,)*2000000)
it requires 126 msec. It's large and I don't even need to initialize the array. I don't know Python internals but I assume that the statement generate tons on malloc() (memory allocator) and free() (memory deallocator).
Is there another way to create a very large Python array?
This is much faster, because it doesn't create a long, temporary tuple:
tb = array.array('i', (0,)) * 2000000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With