[Numpy-discussion] Tuple outer product?

Keith Goodman kwgoodman@gmail....
Fri Sep 25 13:53:39 CDT 2009


On Fri, Sep 25, 2009 at 11:05 AM, Mads Ipsen <mpi@comxnet.dk> wrote:
> Sure, and you could do the same thing using two nested for loops. But
> its bound to be slow when the arrays become large (and they will). The
> question is whether it can be done in pure numpy. An output like
>
> [[[1,4],[1,5],[1,6]],[[2,4],[2,5],[2,6]],[[3,4],[3,5],[3,6]]]
>
> is also OK.

This doesn't work. But maybe someone can make it work:

>> x = np.array([1,2,3])
>> y = np.array([4,5,6])
>>
>> a = np.ones((3,3,2), dtype=np.int)
>> a[:,:,0] = x
>> a[:,:,1] = y
>> a.tolist()
   [[[1, 4], [2, 5], [3, 6]], [[1, 4], [2, 5], [3, 6]], [[1, 4], [2,
5], [3, 6]]]


More information about the NumPy-Discussion mailing list