I have two numpy arrays like this,
data1 = np.array([[17, 48],
[17, 53],
[17, 55]])
data2 = np.array([100,200])
I want to combine those arrays by adding 1 at the beginning of the each one.
I tried,
out = []
for i in data1:
for j in data2:
out.append([1,i,j])
np.array(out)
#array([[1, array([17, 48]), 100],
# [1, array([17, 48]), 200],
# [1, array([17, 53]), 100],
# [1, array([17, 53]), 200],
# [1, array([17, 55]), 100],
# [1, array([17, 55]), 200]], dtype=object)
But the output is not the one I desire. The expected one is like below.
data_desired = np.array([[1,17,48,100],
[1,17,48,200],
[1,17,53,100],
[1,17,53,200],
[1,17,55,100],
[1,17,55,200]])
By the way, using loop seems also wrong to me. Maybe there exist some other alternatives like broadcasting, newaxis etc?
Thanks in advance!