我是 python 的初学者,我的问题是我有 4 个数组,其中有 x 个项目:
persons_id = [ 78694, 51203, ... ]
dates = [ '20072017', '19072017', ... ]
codes = [ 1500, 0606, ... ]
ranges = [ 70, 60, ... ]
我想做的是(在循环中)产生这种输出:
reporting = numpy.array([persons_id[0],
dates[0],
codes[0],
ranges[0]],
[persons_id[1],
dates[1],
codes[1],
ranges[1]],
[...])
提前谢谢
最佳答案
选项 1
np.vstack
np.vstack((persons_id, dates, codes, ranges)).T
array([['78694', '20072017', '1500', '70'],
['51203', '19072017', '606', '60']],
dtype='<U21')
选项 2
np.stack(..., axis=1)
np.stack((persons_id, dates, codes, ranges), axis=1)
array([['78694', '20072017', '1500', '70'],
['51203', '19072017', '606', '60']],
dtype='<U21')
关于Python-如何将数组添加到唯一的 numpy 数组?每个数组必须代表我的 numpy 数组中的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46952742/