我有三个清单,
list1=['10','20','30']
list2=['40','50','60']
list3=['70','80','90']
我想从这些列表中创建一个numpy数组。我正在使用以下代码:
import numpy as np
list1=['10','20','30']
list2=['40','50','60']
list3=['70','80','90']
data = np.array([[list1],[list2],[list3]])
print data
我的输出为:
[[['10' '20' '30']]
[['40' '50' '60']]
[['70' '80' '90']]]
但我期待输出为:
[[10 20 30]
[40 50 50]
[70 80 90]]
有人可以帮我解决这个问题吗?
答案 0 :(得分:2)
指定dtype
:
>>> import numpy as np
>>> list1=['10','20','30']
>>> list2=['40','50','60']
>>> list3=['70','80','90']
>>> np.array([list1, list2, list3], dtype=int)
array([[10, 20, 30],
[40, 50, 60],
[70, 80, 90]])
dtype
:数据类型,可选阵列所需的数据类型。如果没有给出,则类型将 被确定为保持物体所需的最小类型 序列。 ...