Making a 2 dimensional list/matrix with different number of columns for each row
Making a 2 dimensional list/matrix with different number of columns for each row I would like to make a list or matrix that has a known number of rows(3), but for each row the number of elements will be different. So it could look something like this: [[4, 6, 8], [1, 2, 3, 4], [0, 2, 3, 4, 8]] Each row will have a known maximum of elements(8). So far I have tried the following: Sets1=np.zeros((3,8)) for j in range(3): Sets1[0,:]=[i for i, x in enumerate(K[:-1]) if B[x,j]==1 or B[x+1,j]==1] I want this because I want to have a list for each j in range(3) over which I can do a for loop and add constraints to my ILP. Any help will be greatly appreciated! Final expected output for the given sample? – Divakar Jun 29 at 8:35 You shouldn't call that a matrix because matrix is a rectangular array of numbers. It's...
