[Python-ideas] Respectively and its unpacking sentence

Mirmojtaba Gharibi mojtaba.gharibi at gmail.com
Thu Jan 28 03:29:17 EST 2016


On Wed, Jan 27, 2016 at 4:53 PM, Chris Barker <chris.barker at noaa.gov> wrote:

> On Wed, Jan 27, 2016 at 9:12 AM, Mirmojtaba Gharibi <
> mojtaba.gharibi at gmail.com> wrote:
>
>>
>>
>> MATLAB has a built-in easy way of achieving component-wise operation and
>> I think Python would benefit from that without use of libraries such as
>> numpy.
>>
>
> I've always thought there should be a component-wise operations in Python.
> The wlay to do it now is somthing like:
>
> [i + j for i,j in zip(a,b)]
>
> is really pretty darn wordy, compared to :
>
> a_numpy_array + another_numpy array
>
> (similar in matlab).
>
> But maybe an operator is the way to do it. But it was long ago decide dnot
> to introduce a full set of extra operators, alla matlab:
>
> .+
> .*
> etc....
>
> rather, it was realized that for numpy, which does element-wise operations
> be default, matrix multiplication was really the only non-elementwise
> operation widely used, so the new @ operator was added.
>
> And we're kind of stuck --even if we added a full set, then in numpy, the
> regular operators would be element wise, but for built-in Python sequences,
> the special ones would be elementwise -- really confusing!
>
> if you really want this, I'd make your own sequences that re-define the
> operators.
>
Problem is you always forego the hassle of subclassing at that exact moment
that you need element-wise and just use for loops. So it's almost always
not worth the hassle.

>
> Or just use Numpy... you can use object arrays if you want to handle
> non-numeric values:
>
> In [*4*]: a1 = np.array(["this", "that"], dtype=object)
>
> In [*5*]: a2 = np.array(["some", "more"], dtype=object)
>
> In [*6*]: a1 + a2
>
> Out[*6*]: array(['thissome', 'thatmore'], dtype=object)
> -CHB
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160128/302e1a5e/attachment.html>


More information about the Python-ideas mailing list