[MATRIX-SIG] reverse of take?

Andrew P. Mullhaupt amullhau@ix.netcom.com
Thu, 26 Jun 1997 23:07:10 -0400


At 06:07 PM 6/26/97 -0700, Johann Hibschman wrote:
>On Thu, 26 Jun 1997, Andrew P. Mullhaupt wrote:
>
>> This could easily be added to NumPy (along with a couple of other really
>> useful forms of indexing). The long history of successful use of the
>> highly flexible indexing in S is a 'proof of concept'.
>
>Hmm.  Would it be acceptable to define (in a separate extension module)
>a function to do this, or do you feel that the built-in syntax is
>necessary?
>
>I haven't done much with the NumPy internals, but I'd think that it would
>be almost trivial to write a simple extension to do
>
>	multi_set(array, indices, values)
>
>by implementing a C for-loop over the indices.  Is there a hidden subtlety
>that I'm missing?

There are a couple points.

First, it _looks_ a lot better to anyone who has used an array language to
do

        array[indices] = values

instead. It is also a _lot_ easier to remember, and it does the expected
thing. A function such as "multi_set" may or may not be suggestive to the
programmer.
Consider that the "function style" code for

        z[k] = foo(x[k], y[k])

looks something like

        multi_set(z, k, foo(multi_get(x, k), multi_get(y, k)))

and we haven't even started to deal with anything slippery.

Second, you want to put this operation where it will be exposed to
inheritance,
etc. so you want it to be a _method_. Since it conceptually replaces an
existing method, it's better to use that syntax. I think you can get this
pretty easily with __setitem__  or __setslice__, so the syntax shouldn't
really be an issue.

Later,
Andrew Mullhaupt

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________