[Python-ideas] Vectorization [was Re: Add list.join() please]

David Mertz mertz at gnosis.cx
Mon Feb 4 11:12:08 EST 2019


On Mon, Feb 4, 2019 at 7:14 AM Kirill Balunov <kirillbalunov at gmail.com>
wrote:

> len(v)   # -> 12
>
> v[len]   # -> <Vector of [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]>
>
>
> In this case you can apply any function, even custom_linked_list from
> my_inhouse_module.py.
>

I think I really like this idea.  Maybe as an extra spelling but still
allow .apply() to do the same thing. It feels reasonably intuitive to me.
Not *identical to* indexing in NumPy and Pandas, but sort of in the same
spirit as predicative or selection based indices.

What do other people on this thread think? Would you learn that easily?
Could you teach it?


> >>> v[1:]
> <Vector of ['Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
> 'Nov', 'Dec']>
> >>> v[i[1:]] # some helper class `i`
> <Vector of ['an', 'eb', 'ar', 'pr', 'ay', 'un', 'ul', 'ug', 'ep', 'ct',
> 'ov', 'ec']>
>
>
This feels more forced, unfortunately.  Something short would be good, but
not sure I like this.  This is really just a short spelling of
pandas.IndexSlice or numpy.s_  It came up in another thread some months
ago, but there is another proposal to allow the obvious spelling
`slice[start:stop:sep]` as a way of creating slices.

Actually, I guess that's all halfway for the above.  We'd need to do this
still:

v[itemgetter(IndexSlicer[1:])]


That's way too noisy.  I guess I just don't find the lowercase `i` to be
iconic enough.  I think with a better SHORT name, I'd like:

v[Item[1:]]


 Maybe that's not the name?

-- 
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/20190204/546e6d8b/attachment-0001.html>


More information about the Python-ideas mailing list