# [Numpy-discussion] Quick array value assignment based on common values

Gökhan Sever gokhansever@gmail....
Wed Aug 4 20:00:37 CDT 2010

```On Wed, Aug 4, 2010 at 6:59 PM, <PHobson@geosyntec.com> wrote:

> Hey folks,
>
> I've one array, x, that you could define as follows:
> [[1, 2.25],
>  [2, 2.50],
>  [3, 2.25],
>  [4, 0.00],
>  [8, 0.00],
>  [9, 2.75]]
>
> Then my second array, y, is:
> [[1, 0.00],
>  [2, 0.00],
>  [3, 0.00],
>  [4, 0.00],
>  [5, 0.00],
>  [6, 0.00],
>  [7, 0.00],
>  [8, 0.00],
>  [9, 0.00],
>  [10,0.00]]
>
> Is there a concise, Numpythonic way to copy the values of x[:,1] over to
> y[:,1] where x[:,0] = y[:,0]? Resulting in, z:
> [[1, 2.25],
>  [2, 2.50],
>  [3, 2.25],
>  [4, 0.00],
>  [5, 0.00],
>  [6, 0.00],
>  [7, 0.00],
>  [8, 0.00],
>  [9, 2.75],
>  [10,0.00]]
>
> My current task has len(x) = 25000 and len(y) = 350000 and looping through
> is quite slow unfortunately.
>
> Many thanks,
> -paul
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

My simplest approach would be:

y[x[:0]-1] = x

# Providing the arrays are nicely ordered and 1st column x is all integer.

--
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100804/4cdb65c1/attachment-0001.html
```

More information about the NumPy-Discussion mailing list