[Numpy-discussion] Tuple outer product?

Gökhan Sever gokhansever at gmail.com
Fri Sep 25 13:58:37 EDT 2009


On Fri, Sep 25, 2009 at 12:45 PM, Mads Ipsen <mpi at 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 at quantumwise.com |
> +------------------------------+-----------------------------+
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



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


More information about the NumPy-Discussion mailing list