I want to create a 2D numpy array of dimensions Nx2, in python. I want to create this by using 2 for loops. I can easily build this array in Matlab with the following code
matrix = [];
for i = 1:3
for j = 1:4
temp = [i, j];
matrix = [matrix; temp];
end
end
I have tried already numerous times, but failed. Usually, the error that I get is related to the sizes of arrays not matching when I run the for loops.
The output of the code is
matrix =
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4
3 1
3 2
3 3
3 4
np.zeros((100,100))create a 2-D array filled with zeros. It would be clear if you add expected output to the question.[]is 0x0;[[]; [1,2]]joins that with a 1x2,expanding shapes as needed. Innumpyarrays may be 0d,1d etc.np.concatenateis picky about matching dimensions.np.appendis a poorly conceived front end toconcatenate.