簡體   English   中英

Python:從 numpy.ndarray 轉換為列表:掛起

[英]Python : conversion from numpy.ndarray to list : getting hung

我有一個名為word_vector的列表,其每個元素的類型都是“numpy.ndarray”。

print(word_vector)

output:

[array([0., 0., 0., ..., 0., 0., 0.]), array([0., 0., 0., ..., 0., 0., 0.]), array([0., 0., 0., ..., 0., 0., 0.]), array([0., 0., 0., ..., 0., 0., 0.])]

我想將列表中每個元素的類型轉換為列表。 所以我寫了這段代碼:

word_vector_list = []
for arr in word_vector:
    list_ = arr.tolist()
    word_vector_list.append(list_)
    
print(word_vector_list) 

程序反復掛起。 我得到了這個例外:

IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)

列表中每個元素(數組類型)的長度為:

print(len(arr))

output:

4395

我不完全確定您的程序為何掛起。 嘗試像這樣使用列表理解,它應該會更好:

word_vector_list = [list(x) for x in word_vector]

如果它仍然不起作用,請嘗試增加 iopub 數據速率。 要提高 iopub 數據速率,請在終端中運行:

jupyter notebook --NotebookApp.iopub_data_rate_limit=1.0e10

希望這可以幫助:)

2d np 數組可以直接通過.tolist function 更改為列表列表。

也看到這里

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM