[Numpy-discussion] Efficiently defining a multidimensional array

Citi, Luca lciti at essex.ac.uk
Thu Aug 27 17:24:15 EDT 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