本文簡要介紹 python 語言中  numpy.ndarray.tolist  的用法。
- 用法:- ndarray.tolist()
- 將數組作為 Python 標量的 - a.ndim-levels 深度嵌套列表返回。- 將數組數據的副本作為(嵌套)Python 列表返回。數據項通過 - item函數轉換為最接近的兼容內置 Python 類型。- 如果 - a.ndim為 0,那麽由於嵌套列表的深度為 0,它根本就不是一個列表,而是一個簡單的 Python 標量。- none:
 
- y: 對象,或對象列表,或對象列表列表,或……
- 可能嵌套的數組元素列表。 
 
 - 參數:- 返回:- 注意:- 該數組可以通過 - a = np.array(a.tolist())重新創建,盡管這有時可能會丟失精度。- 例子:- 對於一維數組, - a.tolist()與- list(a)幾乎相同,除了- tolist將 numpy 標量更改為 Python 標量:- >>> a = np.uint32([1, 2]) >>> a_list = list(a) >>> a_list [1, 2] >>> type(a_list[0]) <class 'numpy.uint32'> >>> a_tolist = a.tolist() >>> a_tolist [1, 2] >>> type(a_tolist[0]) <class 'int'>- 此外,對於二維數組, - tolist遞歸應用:- >>> a = np.array([[1, 2], [3, 4]]) >>> list(a) [array([1, 2]), array([3, 4])] >>> a.tolist() [[1, 2], [3, 4]]- 此遞歸的基本情況是一個 0D 數組: - >>> a = np.array(1) >>> list(a) Traceback (most recent call last): ... TypeError: iteration over a 0-d array >>> a.tolist() 1
相關用法
- Python numpy ndarray.tobytes用法及代碼示例
- Python numpy ndarray.tostring用法及代碼示例
- Python numpy ndarray.transpose用法及代碼示例
- Python numpy ndarray.astype用法及代碼示例
- Python numpy ndarray.flat用法及代碼示例
- Python numpy ndarray.setflags用法及代碼示例
- Python numpy ndarray.setfield用法及代碼示例
- Python numpy ndarray.sort用法及代碼示例
- Python numpy ndarray.real用法及代碼示例
- Python numpy ndarray.strides用法及代碼示例
- Python numpy ndarray.itemset用法及代碼示例
- Python numpy ndarray.__class_getitem__用法及代碼示例
- Python numpy ndarray.partition用法及代碼示例
- Python numpy ndarray.flatten用法及代碼示例
- Python numpy ndarray.resize用法及代碼示例
- Python numpy ndarray.dtype用法及代碼示例
- Python numpy ndarray.imag用法及代碼示例
- Python numpy ndarray.dot用法及代碼示例
- Python numpy ndarray.size用法及代碼示例
- Python numpy ndarray.fill用法及代碼示例
- Python numpy ndarray.item用法及代碼示例
- Python numpy ndarray.nbytes用法及代碼示例
- Python numpy ndarray.copy用法及代碼示例
- Python numpy ndarray.ctypes用法及代碼示例
- Python numpy ndarray.view用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.ndarray.tolist。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
