如何将几个numpy数组合并为单个字符串表示?

时间:2016-05-06 20:59:24

标签: arrays numpy

我有几个numpy数组:

X = np.array([0,0,0,0,1,1,1,1])
Y = np.array([0,0,1,1,0,0,1,1])
Z = np.array([0,1,0,1,0,1,0,1])

我如何使用它们来生成这个:

array(['0_0_0',
       '0_0_1',
       '0_1_0',
       '0,1,1',
       ...
      ], dtype='|S1')

1 个答案:

答案 0 :(得分:0)

解决方案

np.array(["_".join(row.astype('|S1')) for row in np.concatenate([[X], [Y], [Z]]).T])