python - 从嵌套列表中删除不需要的文本
问题描述
我希望能够删除一些我不想在我的列表中出现的单词。
代码:
contour = cnt
stopwords = ['array', 'dtype=int32']
for word in list(contour):
if word in stopwords:
contour.remove(word)
print(contour)
输出:
[array([[[21, 21]],
[[21, 90]],
[[90, 90]],
[[90, 21]]], dtype=int32)]
FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if word in stopwords:
如何删除dtype=int32
and array
,同时使列表只是两点的列表?
前任:
[[21, 21],
[21, 90],
[90, 90],
[90, 21]]
解决方案
使用numpy.ndarray.tolist()
:
import numpy as np
l = np.array(
[np.array([[[21, 21]],
[[21, 90]],
[[90, 90]],
[[90, 21]]], dtype="int32")]
)
l.tolist()
输出:
[[[[21, 21]], [[21, 90]], [[90, 90]], [[90, 21]]]]
推荐阅读
- python - 如何从文本句子中删除重复字符?
- r - 错误:R 3.5.3 上的 RcppArmadillo 包延迟加载失败
- python - 从python中的两个列表创建字典
- php - 如何修复“类”不是有效的实体或映射的超类。? Symfony 2.8
- reactjs - 结合 gatsby-plugin-google-analytics 在窗口中查找 Google Analytics 对象
- javascript - 使用 += 获取总和在这里不起作用。为什么?
- python - What are argument types for fit() function in keras?
- testing - 如何在小部件测试期间存根不属于类的函数?
- redirect - Bitnami Ghost 不断重定向到 127.0.0.1,但仅在移动设备上
- html - 有没有办法在 CSS 中使用 Angular 路由器参数?