Multiplying every element of one array by every element of another array
问题 Say I have two arrays, import numpy as np x = np.array([1, 2, 3, 4]) y = np.array([5, 6, 7, 8]) What's the fastest, most Pythonic, etc., etc. way to get a new array, z , with a number of elements equal to x.size * y.size , in which the elements are the products of every pair of elements (x_i, y_j) from the two input arrays. To rephrase, I'm looking for an array z in which z[k] is x[i] * y[j] . A simple but inefficient way to get this is as follows: z = np.empty(x.size * y.size) counter = 0