Subtracting numpy arrays of different shape efficiently
You need to extend the dimensions of X with None/np.newaxis to form a 3D array and then do subtraction by w. This would bring in broadcasting into play for this 3D operation and result in an output with a shape of (5,n,3). The implementation would look like this – X[:,None] – w # or X[:,np.newaxis] … Read more