np.array轉換為list,嵌套的python list轉成一個一維的python list


np.array轉換為list

1
meitan = shuju.iloc[start:end, 1:2] 2 3 zhengqi = shuju.iloc[start:end,2:3] 4 print(type(list(l))) 5 newmeitan = np.array(meitan) #[[][][]] 6 newzhengqi = np.array(zhengqi)#[[][][]] 7 print("轉換前",newzhengqi) 8 newmeitan = newmeitan.reshape(1, len(newmeitan)).tolist() # [[2,1,1]] 9 10 newzhengqi = newzhengqi.reshape(1, len(newzhengqi)).tolist() # [[2,1,1]]
   print("轉換后",newzhengqi)
 
        
顯示如下,第一個是轉換前,第二個轉化后
1
轉換前 [[ 63.13064957] 2 [ 66.2085495 ] 3 [ 67.42173767] 4 [ 66.29841614] 5 [ 67.2869339 ] 6 [ 65.04029846] 7 [ 67.9384613 ] 8 [ 69.80317688] 9 [ 66.47814941]] 10 轉換后 [[63.1306495666504, 66.2085494995117, 67.4217376708984, 66.2984161376953, 67.2869338989258, 65.0402984619141, 67.9384613037109, 69.8031768798828, 66.4781494140625]]

 

嵌套的python list轉成一個一維的python list
1
x = [[2],[23],[3]] 2 y = sum(x,[]) 3 print(y)
顯示如下
1
[2, 23, 3]

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM