Python-如何将数组添加到唯一的numpy数组中?每个数组必须表示我的numpy数组中的一行
我是python的完全初学者,我的问题是我有4个数组,其中包含x项:Python-如何将数组添加到唯一的numpy数组中?每个数组必须表示我的numpy数组中的一行,python,arrays,numpy,Python,Arrays,Numpy,我是python的完全初学者,我的问题是我有4个数组,其中包含x项: persons_id = [ 78694, 51203, ... ] dates = [ '20072017', '19072017', ... ] codes = [ 1500, 0606, ... ] ranges = [ 70, 60, ... ] 我想做的是(在循环中)产生这种输出: reporting = numpy.array([persons_id[0], dat
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
如果我确信我的所有阵列都具有相同的形状,您的解决方案将是完美的。@dearblackswan请查看此链接以了解如何填充列表:。然而,如果您只想删除额外的值,那就更简单了。
np.vstack((persons_id, dates, codes, ranges)).T
array([['78694', '20072017', '1500', '70'],
['51203', '19072017', '606', '60']],
dtype='<U21')
np.stack((persons_id, dates, codes, ranges), axis=1)
array([['78694', '20072017', '1500', '70'],
['51203', '19072017', '606', '60']],
dtype='<U21')