[Numpy-discussion] Tuple outer product?

Gökhan Sever gokhansever@gmail....
Fri Sep 25 12:58:37 CDT 2009


On Fri, Sep 25, 2009 at 12:45 PM, Mads Ipsen <mpi@comxnet.dk> wrote:

> Is there a numpy operation on two arrays, say [1,2,3] and [4,5,6], that
> will yield:
>
> [[(1,4),(1,5),(1,6)],[(2,4),(2,5),(2,6)],[(3,4),(3,5),(3,6)]]
>
> Any suggestions are most welcome.
>
> Mads
>
>

I don't know if there is a function in numpy library, but it is a simple one
isn't it?

ipython --pylab

I[1]: a = array([1,2,3])

I[2]: b = array([4,5,6])

I[3]: [zip(ones(a.size, dtype=int)*a[i], b) for i in range(len(a))]
O[3]: [[(1, 4), (1, 5), (1, 6)], [(2, 4), (2, 5), (2, 6)], [(3, 4), (3, 5),
(3, 6)]]



>
> --
> +------------------------------------------------------------+
> | Mads Ipsen, Scientific developer                           |
> +------------------------------+-----------------------------+
> | QuantumWise A/S              | phone:         +45-29716388 |
> | Nørresøgade 27A              | www:    www.quantumwise.com |
> | DK-1370 Copenhagen, Denmark  | email:  mpi@quantumwise.com |
> +------------------------------+-----------------------------+
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090925/6dad6e02/attachment.html 


More information about the NumPy-Discussion mailing list