This is the list of lists I have
[[3, 2, 1, 2, 2, 3, 1], [3, 4, 2, 3, 1, 3, 2], [1, 2, 4, 1, 2, 4, 1], [3, 4, 3, 1, 4, 1, 2], [3, 1, 4, 1, 2, 3, 4], [3, 1, 3, 3, 2, 4, 1], [3, 2, 1, 2, 2, 3, 1], [3, 2, 1, 2, 2, 3, 1], [3, 2, 1, 2, 2, 3, 1], [3, 2, 1, 2, 2, 3, 1], [1, 2, 1, 2, 2, 3, 1], [4, 3, 1, 4, 1, 2, 3], [3, 2, 2, 1, 2, 1, 2], [3, 2, 1, 2, 2, 3, 1], [2, 2, 2, 1, 2, 4, 1], [1, 4, 3, 2, 2, 1, 4],....,[1, 2, 1, 1, 3, 1, 2], [3, 3, 4, 2, 3, 2, 1], [3, 2, 1, 2, 2, 2, 1], [4, 2, 1, 1, 4, 3, 4], [4, 4, 1, 2, 2, 4, 3], [3, 4, 3, 2, 2, 1, 4], [4, 1, 1, 3, 3, 4, 3]]
I tried numpy.array but it gives a 1D array like this
[[3, 2, 1, 2, 2, 3, 1] [3, 1, 2, 4, 1, 4, 4] [1, 2, 4, 1, 2, 4, 1] ...,
[4, 4, 1, 2, 2, 4, 3] [3, 4, 3, 2, 2, 1, 4] [4, 1, 1, 3, 3, 4, 3]]
whose size is (15410,) which means it's not being created as 2D.
I even tried using np.vstack and np.concatenate. But it says all lists must be of the same dimension. They are all of the same length. I don't understand why I'm getting this error. I am using python3. Also is there a better way to convert a list of lists to a 2D numpy array?
Edit: The code that converts the list of lists to numpy array:
print(testFeature)
x_test=np.array(testFeature)
print(x_test)
print (x_test.shape)
If you list is called l, the code below should help you find the offending elements.
for i,v in enumerate(l):
if(len(v)!=len(l[0])):
print('bad element {} at {}'.format(v,i))
Fixing these elements should help fix the problem.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments