[Python-ideas] Add a datatype collections.ListView

David Mertz mertz at gnosis.cx
Thu Apr 17 23:11:44 CEST 2014


On Thu, Apr 17, 2014 at 9:28 AM, Nathaniel Smith <njs at pobox.com> wrote:
>FWIW, numpy arrays do indeed have to be of uniform type, but one of
>the supported uniform types is "arbitrary Python object".

I did not know that!  However, now that I do:

% python3 ListView.py
         A bunch of slices from list: 3.76 seconds
A bunch of slices from DummyListView: 3.33 seconds
     A bunch of slices from ListView: 0.03 seconds
  A bunch of slices from numpy.array: 0.30 seconds

The only things I changed are to add 'import numpy' at the top, and add
'np.array' to the loop of containers to try out (I also bumped up the
iterations of the two loops from 8/3 times to 10/5 times just to make
things take a little longer and get slightly more accurate timing I hope).


On Thu, Apr 17, 2014 at 9:28 AM, Nathaniel Smith <njs at pobox.com> wrote:

> On Thu, Apr 17, 2014 at 4:49 PM, David Mertz <mertz at gnosis.cx> wrote:
> > What I'd really like is a "ListView" that acts something like NumPy's
> > non-copying slices.  However numpy, of course, only deals with arrays and
> > matrices of uniform numeric types.  I want a non-copying "slice" of a
> list
> > of generic Python objects.
>
> FWIW, numpy arrays do indeed have to be of uniform type, but one of
> the supported uniform types is "arbitrary Python object".
>
> In [1]: a = np.array([1, "hello", None])
>
> In [2]: a
> Out[2]: array([1, 'hello', None], dtype=object)
>
> In [3]: a[1:]
> Out[3]: array(['hello', None], dtype=object)
>
> There are other trade-offs though, e.g., no .append() or .find() methods.
>
> -n
>
> --
> Nathaniel J. Smith
> Postdoctoral researcher - Informatics - University of Edinburgh
> http://vorpus.org
>



-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140417/f76595d0/attachment.html>


More information about the Python-ideas mailing list