[Numpy-discussion] Tuple outer product?
Mads Ipsen
mpi at comxnet.dk
Fri Sep 25 18:38:53 EDT 2009
Alan G Isaac wrote:
> 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
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
Yes, but it should also work for [2.1,3.2,4.5] combined with
[4.6,-2.3,5.6] - forgot to tell that.
Mads
--
+------------------------------------------------------------+
| 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 |
+------------------------------+-----------------------------+
More information about the NumPy-Discussion
mailing list