I want to create a Cartesian product of two numpy so that the first numpy will be the rows and the second will be the columns. For example get these two numpys:
a = np.array([0,0])
b = np.array([0,1,2,3])
The expected result should be 2d numpy like this:
[[0 0 0]
[0 0 1]
[0 0 2]
[0 0 3]]
The following code does not produce the requested result:
a = np.array([0,0])
b = np.array([0,1,2,3])
_new_ = []
for idx in range(len(a)):
for i in a:
newArr = np.append(a[idx], b)
_new_.append(newArr)
print(np.stack(_new_))
What needs to be changed to produce the desired result?
ahas 2 elements, but the result has 3 columns. If appending lists, I'd suggest sticking with lists, and don't try to usenp.append(that's a nasty function).