如何将两个numpy数组加在一起?

时间:2018-06-25 12:05:40

标签: python arrays numpy multidimensional-array concat

在看起来很简单的事情上遇到了一些麻烦。我想加入这两个数组以满足输出:

array([['category_1', '4500', '5000'], ['category_2', '3200', '5000'], ['category_3', '3000', '5000'], ['category_4', '2000', '5000']], dtype='<U8')

我有一些数据

data = np.array([['category_1', '4500', '5000'], ['category_2', '3200', '5000']])

我还有其他数据

other_data = np.array([['category_3', '3000', '5000'], ['category_4', '2000', '5000'])

当我这样做时,我得到这个错误

np.concatenate(data, other_data)

TypeError: only integer scalar arrays can be converted to a scalar index

1 个答案:

答案 0 :(得分:1)

data = np.array([['category_1', '4500', '5000'], ['category_2', '3200', '5000']])
other_data = np.array([['category_3', '3000', '5000'], ['category_4', '2000', '5000']])
np.concatenate((data, other_data), axis=0)