如何将一个转换numpy数组的元组变换转换为2d numpy数组

时间:2017-06-26 09:53:10

标签: python numpy vector

我有这样的numpy数组:

a = [(20111205000000,  15.94,  16.04,  15.7 ,  15.95,  11349137.)
 (20111206000000,  15.95,  15.95,  15.95,  15.95,         0.)
 (20111207000000,  15.9 ,  16.15,  15.86,  16.05,  14862428.)
 (20111208000000,  16.05,  16.13,  15.81,  15.94,  18705208.)]

我不能使用这样的切片[1:3,2:3]。所以我想把这个矢量改为:

 [[20111205000000  15.94  16.04  15.7  15.95  11349137]
  [20111206000000  15.95  15.95  15.95  15.95  0]
  [20111207000000  15.9  16.15  15.86  16.05  14862428]
  [20111208000000  16.05  16.13  15.81  15.94  18705208]]

请帮帮我,谢谢。

2 个答案:

答案 0 :(得分:0)

您可以使用:

np.array([list(i) for i in a])

答案 1 :(得分:0)

你可以使用像这样的列表理解

z=[[x for x in b] for b in a]
np.array(z)
array([[  2.01112050e+13,   1.59400000e+01,   1.60400000e+01,
      1.57000000e+01,   1.59500000e+01,   1.13491370e+07],
   [  2.01112060e+13,   1.59500000e+01,   1.59500000e+01,
      1.59500000e+01,   1.59500000e+01,   0.00000000e+00],
   [  2.01112070e+13,   1.59000000e+01,   1.61500000e+01,
      1.58600000e+01,   1.60500000e+01,   1.48624280e+07],
   [  2.01112080e+13,   1.60500000e+01,   1.61300000e+01,
      1.58100000e+01,   1.59400000e+01,   1.87052080e+07]])