[Numpy-discussion] Efficiently defining a multidimensional array

Citi, Luca lciti@essex.ac...
Thu Aug 27 16:24:15 CDT 2009


One solution I can think of still requires one loop (instead of three):

import numpy as np
a = np.arange(12).reshape(3,4)
b = np.arange(15).reshape(3,5)
z = np.empty(a.shape + (b.shape[-1],))
for i in range(len(z)):
    z[i] = np.add.outer(a[i], b[i])



More information about the NumPy-Discussion mailing list