<div dir="ltr">Numpy's outer product works fine with vectors.  However, I seem to always want len(outer(a, b).shape) to be equal to len(a.shape) + len(b.shape).  Wolfram-alpha seems to agree <a href="https://reference.wolfram.com/language/ref/Outer.html">https://reference.wolfram.com/language/ref/Outer.html</a> with respect to matrix outer products.  My suggestion is to define outer as defined below.  I've contrasted it with numpy's current outer product.<div><div><br></div><div><div>In [36]: def a(n): return np.ones(n)</div><div><br></div><div>In [37]: b = a(())</div><div><br></div><div>In [38]: c = a(4)</div><div><br></div><div>In [39]: d = a(5)</div><div><br></div><div>In [40]: np.outer(b, d).shape</div><div>Out[40]: (1, 5)</div><div><br></div><div>In [41]: np.outer(c, d).shape</div><div>Out[41]: (4, 5)</div><div><br></div><div>In [42]: np.outer(c, b).shape</div><div>Out[42]: (4, 1)</div><div><br></div><div>In [43]: def outer(a, b):</div><div>    return a[(...,) + len(b.shape) * (np.newaxis,)] * b</div><div>   ....:</div><div><br></div><div>In [44]: outer(b, d).shape</div><div>Out[44]: (5,)</div><div><br></div><div>In [45]: outer(c, d).shape</div><div>Out[45]: (4, 5)</div><div><br></div><div>In [46]: outer(c, b).shape</div><div>Out[46]: (4,)</div></div></div><div><br></div><div>Best,</div><div><br></div><div>Neil</div></div>