0
Need help here
Any idea why this code is not converting the inner list?: #the code: import numpy as np malist = [1,2,3, [7,8,9], 4,5,6] print(malist) arrays = np.array(malist) print(arrays) #the output: [1, 2, 3, [7, 8, 9], 4, 5, 6] [1 2 3 list([7, 8, 9]) 4 5 6] [Program finished]
2 Respuestas
0
It is because they are of different data type. Numpy works with array of the same dimension.
Numpy dosen't know what to do with it that's why it converted it to a list so that it could be dsame with others
import numpy as np
malist=[[1,2,3],[7,8,9],[4,5,6]]
arrays=np.array(malist)
print(arrays)
It should work this way because python understands that it is a 3x3 array
or you can specify that the dtype=object
arrays=np.array(malist, dtype='object')
0
Thanks