On May 18, 2015 9:56 PM, "Fabien" <fabien.mauss...@gmail.com> wrote: > > On 05/18/2015 09:49 PM, Ian Kelly wrote: >> >> It may be possible that lists in CPython could be made to share their >> internal arrays with other lists on a copy-on-write basis, which could >> allow slicing to be O(1) as long as neither list is modified while the >> array is being shared. I expect this would be a substantial piece of >> work, and I don't know if it's something that anybody has looked into. > > > Isn't Numpy doing this (not sure, not a python nor a numpy expert): > > >>> import numpy as np > >>> a = np.array([1,2,3,4]) > >>> b = a[1:] > >>> b[0] = 9 > >>> a > array([1, 9, 3, 4]) > > > Fabien
Numpy arrays use views. Matlab arrays use copy-on-write. But as discussed in the recent thread about string views, these approaches have a memory penalty since they require keeping the original array in memory. And the copy-on-write approach still has a O(k) complexity if you try to make any changes.
-- https://mail.python.org/mailman/listinfo/python-list