numpy vstack

时间:2016-07-01 07:54:04

标签: python numpy


使用numpy vstack表示浮点值时使用指数e-5时出现问题。
item_array和date_array都是numpy.ndarray 当我使用 data = np.vstack((date_array,item_array))时,元素 3.04871703e-05 变为 3.0487170344 。其他元素都很好。有没有人可以帮我解决这个问题?感谢

在[2]中:item_array
出[2]:
数组([0.00000000e + 00,-1.81992510e-03,-9.44964473e-03,
        -3.12464669e-03,-5.42864845e-03,-1.67769866e-03,
          3.04871703e-05 , - 7.81295968e-03,-1.12972557e-02,
        -1.69797339e-02,-1.22161657e-02,-1.93931514e-02,
        -1.11389637e-02,-7.59505250e-03,5.65141213e-03,
         4.81559901e-03,-1.37724956e-02,-1.51201763e-02,
        -2.55894748e-02,-2.48333169e-02,-2.56770574e-02,
        -3.21192961e-02,-2.71028609e-02,-2.84357450e-02])

在[3]中:date_array
出[3]:
array(['“2016-05-03”','“2016-05-04”','“2016-05-05”','“2016-05-06”',
       '“2016-05-07”','“2016-05-08”','“2016-05-09”','“2016-05-10”',
       '“2016-05-11”','“2016-05-12”','“2016-05-13”','“2016-05-14”',
       '“2016-05-15”','“2016-05-16”','“2016-05-17”','“2016-05-18”',
       '“2016-05-19”','“2016-05-20”','“2016-05-21”','“2016-05-22”',
       '“2016-05-23”','“2016-05-24”','“2016-05-25”','“2016-05-26”'],
      D型= '| S12')

在[4]中:data = np.vstack((date_arry,item_array))

在[5]中:数据
出[5]:
array([['“2016-05-03”','“2016-05-04”','“2016-05-05”','“2016-05-06”',
        '“2016-05-07”','“2016-05-08”','“2016-05-09”','“2016-05-10”',
        '“2016-05-11”','“2016-05-12”','“2016-05-13”','“2016-05-14”',
        '“2016-05-15”','“2016-05-16”','“2016-05-17”','“2016-05-18”',
        '“2016-05-19”','“2016-05-20”','“2016-05-21”','“2016-05-22”',
        '“2016-05-23”','“2016-05-24”','“2016-05-25”','“2016-05-26”'],
       ['0.0',' - 0.001819925',' - 0.009449644',' - 0.003124646',
        '-0.005428648',' - 0.001677698','3.0487170344',' - 0.007812959',
        '-0.011297255',' - 0.016979733',' - 0.012216165',' - 0.019393151',
        '-0.011138963',' - 0.007595052','0.0056514121','0.0048155990',
        '-0.013772495',' - 0.015120176',' - 0.025589474',' - 0.024833316',
        '-0.025677057',' - 0.032119296',' - 0.027102860',' - 0.028435744']],
      D型= '| S12')

1 个答案:

答案 0 :(得分:1)

我写了这样的剧本:

import numpy as np

item_array = np.array([0.00000000e+00, -1.81992510e-03, -9.44964473e-03,
                       -3.12464669e-03, -5.42864845e-03, -1.67769866e-03,
                       3.04871703e-05, -7.81295968e-03, -1.12972557e-02,
                       -1.69797339e-02, -1.22161657e-02, -1.93931514e-02,
                       -1.11389637e-02, -7.59505250e-03, 5.65141213e-03,
                       4.81559901e-03, -1.37724956e-02, -1.51201763e-02,
                       -2.55894748e-02, -2.48333169e-02, -2.56770574e-02,
                       -3.21192961e-02, -2.71028609e-02, -2.84357450e-02])

date_array = np.array(['"2016-05-03"', '"2016-05-04"', '"2016-05-05"', '"2016-05-06"',
                       '"2016-05-07"', '"2016-05-08"', '"2016-05-09"', '"2016-05-10"',
                       '"2016-05-11"', '"2016-05-12"', '"2016-05-13"', '"2016-05-14"',
                       '"2016-05-15"', '"2016-05-16"', '"2016-05-17"', '"2016-05-18"',
                       '"2016-05-19"', '"2016-05-20"', '"2016-05-21"', '"2016-05-22"',
                       '"2016-05-23"', '"2016-05-24"', '"2016-05-25"', '"2016-05-26"'])

data = np.vstack((date_array,item_array))

print data

我得到了一个好结果:

[['"2016-05-03"' '"2016-05-04"' '"2016-05-05"' '"2016-05-06"'
  '"2016-05-07"' '"2016-05-08"' '"2016-05-09"' '"2016-05-10"'
  '"2016-05-11"' '"2016-05-12"' '"2016-05-13"' '"2016-05-14"'
  '"2016-05-15"' '"2016-05-16"' '"2016-05-17"' '"2016-05-18"'
  '"2016-05-19"' '"2016-05-20"' '"2016-05-21"' '"2016-05-22"'
  '"2016-05-23"' '"2016-05-24"' '"2016-05-25"' '"2016-05-26"']
 ['0.0' '-0.0018199251' '-0.00944964473' '-0.00312464669' '-0.00542864845'
  '-0.00167769866' '3.04871703e-05' '-0.00781295968' '-0.0112972557'
  '-0.0169797339' '-0.0122161657' '-0.0193931514' '-0.0111389637'
  '-0.0075950525' '0.00565141213' '0.00481559901' '-0.0137724956'
  '-0.0151201763' '-0.0255894748' '-0.0248333169' '-0.0256770574'
  '-0.0321192961' '-0.0271028609' '-0.028435745']]

如果你不写dtype,它应该可以正常工作;)