→ klamathu: 好奇這個[1, 2, [3, 4]]的Dimension是 04/25 07:36
→ dosiris: numpy回應shape是 (3,) 04/25 07:46
推 klamathu: itertools.chain()有符合大大的需求嗎? 04/25 07:59
一樣出現 TypeError: 'int' object is not iterable
→ lycantrope: ...因為numpy直接把它存成object 04/25 09:06
→ lycantrope: 應該有跳warning吧.. 04/25 09:06
list(np.array([1,2,[3,4]]).flatten()) 沒跳出warning 但丟回的結果就是原樣
Out[31]: [1, 2, [3, 4]]
※ 編輯: dosiris (111.250.78.225 臺灣), 04/25/2023 09:26:49
→ lycantrope: 你可以看一下np.array([1,2,[3,4]])的dtype 04/25 09:48
→ dosiris: 謝謝分享! 看來只能自訂指令解決了。學到一課 04/25 11:14
推 a78998042a: import more_itertools; nested_list=[1, 2, [3, 4]] 04/25 17:52
→ a78998042a: result=list(more_itertools.collapse(nested_list)) 04/25 17:52
→ dosiris: 謝謝樓上!原來還有這招,學到了! 04/25 20:07