I want to make all possible combinations of numpy arrays of different sizes into a bigger matrix. For examples a = np.array([1, 2, 3, 4, 5])
, b = np.array([6, 7, 8])
, c = np.array([9, 10, 3, 4, 5])
the output should be:
array([[1., 6., 9.],
[2., 7., 10.],
[3., 8., 3.],
[4., 6., 4.],
[5., 7., 5.],
[1., 8., 10.],
[2., 6., 3.],
[3., 7., 4.],
[4., 8., 5.],
[5., 6., 9.],
.....
[5., 8., 5.])
to cover all possible combinations. Note that array b values are being repeated. I have tried making array of ones and then use broadcasting principle.
arr= np.ones((75,3))
arr[:,0]=arr[:,0]*a
arr[:,1]=arr[:,1]*b
arr[:,2]=arr[:,2]*c
But getting operands could not be broadcast together with shapes.
(Edit) need a solution that can have dynamic number of arrays of variable length. Not necessarily for three arrays.