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]

9th Feb 2022, 8:52 PM
Abdulwahab
Abdulwahab - avatar
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')
10th Feb 2022, 1:35 AM
okonkwo calistus
okonkwo calistus - avatar
0
Thanks
10th Feb 2022, 6:56 AM
Abdulwahab
Abdulwahab - avatar