I'm a complete beginner in python, and my problem is that i have 4 arrays, with x items:
我是一个完全的python初学者,我的问题是我有4个数组,有x个项目:
persons_id = [ 78694, 51203, ... ]
dates = [ '20072017', '19072017', ... ]
codes = [ 1500, 0606, ... ]
ranges = [ 70, 60, ... ]
What i'm trying to do is ( in a loop ) to produce that kind of output:
我想做的是(在循环中)产生这样的输出:
reporting = numpy.array([persons_id[0],
dates[0],
codes[0],
ranges[0]],
[persons_id[1],
dates[1],
codes[1],
ranges[1]],
[...])
Thank you in advance
提前谢谢你
1 个解决方案
#1
4
Option 1np.vstack
选项1 np.vstack
np.vstack((persons_id, dates, codes, ranges)).T
array([['78694', '20072017', '1500', '70'],
['51203', '19072017', '606', '60']],
dtype='<U21')
Option 2np.stack(..., axis=1)
选项2 np.stack(…轴= 1)
np.stack((persons_id, dates, codes, ranges), axis=1)
array([['78694', '20072017', '1500', '70'],
['51203', '19072017', '606', '60']],
dtype='<U21')
#1
4
Option 1np.vstack
选项1 np.vstack
np.vstack((persons_id, dates, codes, ranges)).T
array([['78694', '20072017', '1500', '70'],
['51203', '19072017', '606', '60']],
dtype='<U21')
Option 2np.stack(..., axis=1)
选项2 np.stack(…轴= 1)
np.stack((persons_id, dates, codes, ranges), axis=1)
array([['78694', '20072017', '1500', '70'],
['51203', '19072017', '606', '60']],
dtype='<U21')