[Numpy-discussion] Tuple outer product?

Alan G Isaac aisaac@american....
Fri Sep 25 15:44:52 CDT 2009


On 9/25/2009 4:01 PM, Mads Ipsen wrote:
> a = numpy.array([1,2,3])
> b = numpy.array([4,5,6])
>
> (n,m) = (a.shape[0],b.shape[0])
> a = numpy.repeat(a,m).reshape(n,m)
> b = numpy.repeat(b,n).reshape(m,n).transpose()
> ab = numpy.dstack((a,b))
>
> print ab.tolist()


That's just a slow implementation of meshgrid:
np.meshgrid(a,b).transpose().tolist()
Gives you the same thing.

Alan Isaac


More information about the NumPy-Discussion mailing list