[英]Python Basics: Convert np.array to
I have the following np.array: {0: array([[254, 426],...54, 426]])}
我有以下 np.array:
{0: array([[254, 426],...54, 426]])}
and would like this as desired output: [(444, 703), (623, 543), (691, 177), (581, 26), (482, 42)]
并希望将其作为所需的输出:
[(444, 703), (623, 543), (691, 177), (581, 26), (482, 42)]
How can I do this?我怎样才能做到这一点? I need the variable to be set like in the desired output.
我需要像在所需的输出中一样设置变量。
Thanks a lot.非常感谢。
As it is mentioned in the comments that is not an array but a dictionary.正如评论中提到的,它不是数组而是字典。 can get list of tuples buy doing this:
可以得到元组列表购买这样做:
list(map(tuple, dict[0]))
where dict is your dictionary其中 dict 是你的字典
arr = np.array([1, 2, 3])
print(f'NumPy Array:\n{arr}')
list1 = arr.tolist()
print(f'List: {list1}')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.