1. 程式人生 > >關於內建的list

關於內建的list

問題來源:怎麼在ndarray和list之間進行轉換。

list 轉 numpy

np.array(a)

 

ndarray 轉 list

a.tolist()

 

但是無意中發現list(a)也是可以的。

但是list明明是系統的關鍵字,
list @overload def __init__(self) -> None
Possible types:
• (self: list) -> None
• (self: list, iterable: Iterable[_T]) -> None
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. # (copied from class doc)

查閱文件發現,只要是一個可迭代物件就可以轉換成list物件。