Reputation: 323
I want to be able to remove some words that I don't want inside of my list.
code:
contour = cnt
stopwords = ['array', 'dtype=int32']
for word in list(contour):
if word in stopwords:
contour.remove(word)
print(contour)
output:
[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:
how do I remove dtype=int32
and array
, while making the list just a list of the two points?
ex:
[[21, 21],
[21, 90],
[90, 90],
[90, 21]]
Upvotes: 1
Views: 58
Reputation: 1858
Use numpy.ndarray.tolist()
:
import numpy as np
l = np.array(
[np.array([[[21, 21]],
[[21, 90]],
[[90, 90]],
[[90, 21]]], dtype="int32")]
)
l.tolist()
Output:
[[[[21, 21]], [[21, 90]], [[90, 90]], [[90, 21]]]]
Upvotes: 1