繁体   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