[Python-ideas] Vectorization [was Re: Add list.join() please]
kirillbalunov at gmail.com
Fri Feb 1 11:02:30 EST 2019
пт, 1 февр. 2019 г. в 02:24, Steven D'Aprano <steve at pearwood.info>:
> On Thu, Jan 31, 2019 at 09:51:20AM -0800, Chris Barker via Python-ideas
> > I do a lot of numerical programming, and used to use MATLAB and now
> numpy a
> > lot. So I am very used to "vectorization" -- i.e. having operations that
> > work on a whole collection of items at once.
> > You can imagine that for more complex expressions the "vectorized"
> > can make for much clearer and easier to parse code. Also much faster,
> > is what is usually talked about, but I think the readability is the
> > deal.
> Julia has special "dot" vectorize operator that looks like this:
> L .+ 1 # adds 1 to each item in L
> func.(L) # calls f on each item in L
> The beauty of this is that you can apply it to any function or operator
> and the compiler will automatically vectorize it. The function doesn't
> have to be written to specifically support vectorization.
IMO, the beauty of vector type is that it contains homogeneous data.
Therefore, it allows you to ensure that the method is present for each
element in the vector. The first given example is what numpy is all about
and without some guarantee that L consists of homogeneous data it hardly
make sense. The second one is just `map`. So I can't catch what you are
1. To make an operator form of `map`.
2. To pull numpy into stdlib.
3. Or something else, which is not obvious to me from the examples given.
With kind regards,
> > So what does this have to do with the topic at hand?
> > I know that when I'm used to working with numpy and then need to do some
> > string processing or some such, I find myself missing this
> > -- if I want to do the same operation on a whole bunch of strings, why
> do I
> > need to write a loop or comprehension or map? that is:
> > [s.lower() for s in a_list_of_strings]
> > rather than:
> > a_list_of_strings.lower()
> Using Julia syntax, that might become a_list_of_strings..lower(). If you
> don't like the double dot, perhaps str.lower.(a_list_of_strings) would
> be less ugly.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas