load 包含不同数据类型的txt到同一个array里:

    data = np.loadtxt(filename,delimiter=',', dtype={'names': ('degree', 'old', 'new')\
    ,'formats': ('S16', 'f8', 'f8')})

    #output
    #array([('Business', 200521.0, 358293.0),
    #  ('Computer Science', 15121.0, 39589.0),
    #  ('Education', 108074.0, 101265.0),
    #  ('Engineering', 63642.0, 72654.0),
    #  ('Social Sciences', 100513.0, 172780.0)], 
    # dtype=[('degree', 'S16'), ('old', '<f8'), ('new', '<f8')])

访问各个列:

data.degree
data['degree']

results matching ""

    No results matching ""