Python 3.x 创建混合数据类型的numpy数组

Python 3.x 创建混合数据类型的numpy数组,python-3.x,dictionary,numpy-ndarray,Python 3.x,Dictionary,Numpy Ndarray,例如,我有三本字典: first_dictionary = {'Feature1': array([0, 0, 1, 0]), 'Feature2': array([0, 1, 0, 0]), 'Feature3': array([1, 0, 0])} second_dictionary = { 'Feature4': array([0., 1.]), 'Feature5': array([0.]), 'Feature6': array([0., 1.])} third_dictio

例如,我有三本字典:

first_dictionary = {'Feature1': array([0, 0, 1, 0]),
 'Feature2': array([0, 1, 0, 0]),
 'Feature3': array([1, 0, 0])}

second_dictionary = { 'Feature4': array([0., 1.]),
 'Feature5': array([0.]),
 'Feature6': array([0., 1.])}

third_dictionary = {{'Feature7': array([  0.,   0.,   0., 912.,   0.,
          0.,   0.,   0.,   0.,   0.]),
 'Feature8': array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])}

真正的字典有更多的键(每个大约50个)。我将numpy阵列合并以生成单个1D numpy阵列:


output = []

for dictionary in [first_dictionary,second_dictionary,third_dictionary]:
    for key, value in dictionary.items():
        output += list(value)
    
output_array = np.array(output)

然而,当我这样做的时候,数据类型都被弄乱了,因为我想生成一个最终的numpy数组,它保持原始numpy数组的数据类型

所以我得到的是:

array([  0.,   0.,   1.,   0.,   0.,   1.,   0.,   0.,   1.,   0.,   0.,
         0.,   1.,   0.,   0.,   1.,   0.,   0.,   0., 912.,   0.,   0.,
         0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,
         0.,   0.,   0.,   0.])


然而,正如你们所能看到的,第一个字典只有整数,所以我希望它看起来像:


array([  0,    0,    1,    0,    0,    1,    0,    0,   1,     0,    0,
         0.,   1.,   0.,   0.,   1.,   0.,   0.,   0., 912.,   0.,   0.,
         0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,
         0.,   0.,   0.,   0.])

我怎样才能做到这一点?如有见解,将不胜感激。
旁注:所有词典中的所有numpy数组都是使用np.ndarray创建的,类型设置为None。

您可以通过将numpy数组的dtype设置为
对象来实现这一点

output_array = np.array(output, dtype= object)
输出:
[0 0 1 0 0 1 0 0 1 0 0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 912.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0]