As pointed out in the comments there are several ways to reach your goal.
In [1]: import numpy as np
In [6]: a = np.random.rand(1000)
In [7]: b = np.random.rand(1000)
In [9]: %timeit a - b.reshape((-1,1))
100 loops, best of 3: 2.46 ms per loop
In [10]: %timeit np.subtract.outer(a, b)
100 loops, best of 3: 2.52 ms per loop
It seems that the reshape and the subtract.outer are comparable in speed. However it looks like you need to transpose the result in order to have identical results for both methods
In [18]: a - b.reshape((-1,1)) == np.subtract.outer(a, b).T
array([[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
...,
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True]], dtype=bool)
Edit The second method proposed by @PaulPanzer seems to be the slowest.
In [27]: %timeit np.subtract(*np.ix_(a, b)); a[:, None] - b[None, :]
100 loops, best of 3: 4.99 ms per loop
np.subtract.outer(arr1, arr2)or broadcasting ornp.subtract(*np.ix_(arr1, arr2)); broadcasting:arr1[:, None] - arr2[None, :]arr1 - arr2.reshape((-1,1))numpy.dstacktakes only one argument returns an array. Summin of it yields a scalar. I dont see how this is supposed to work.