# [MATRIX-SIG] reverse of take?

**Andrew P. Mullhaupt
**
amullhau@ix.netcom.com

*Thu, 26 Jun 1997 18:11:53 -0400*

At 05:15 PM 6/26/97 -0400, Aaron Watters wrote:
>*Ok. Just to be perverse, say I want to draw a 1d fractal
*>*border on the huge 2d matrix using only the indices.
*
Just so. Here's how to do it in S, where z is the huge array,
and the x values of the indices are in a vector x, similarly
for y, and v is the vector of corresponding values to assign.
z[cbind(x, y)] <- v
What this does is create an Nx2 matrix with columns x and y, and then
indexes the array z with them. This kind of scatter is really neat
and one of the attractions of the S language. S has by far the nicest
syntax for indexing of all the array languages, and it is the language
closest to Python in terms of object-orientation and argument syntax.
Note that although S is normally very slow compared to Python, the fact
that powerful array indexing is implemented at the "C" level makes up
for a lot of lost ground.
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'.
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
_______________