python是否有类似容器的字典,但是像numpy.array一样快?

时间:2012-10-19 07:56:26

标签: python dictionary numpy

我知道numpy.array比python内置列表快得多,内存也少得多。 有没有像dict那样但速度更快的东西?我只需要存储intintintfloat数据。

1 个答案:

答案 0 :(得分:1)

我会从pandas查看series。正如您从示例中看到的,它适用于np.arrays

import numpy as np

from pandas import *

randn = np.random.randn

In [309]: s = Series(randn(5), index=randn(5))

In [310]: s
Out[310]: 
 1.968290    0.132438
-0.307750    0.158168
 0.288507    2.129288
 1.002813   -0.247056
-0.450041    1.731273

In [311]: foo = np.array([0., 1.5, 1.])

In [312]: s = Series(foo)

In [313]: s
Out[313]: 
0    0.0
1    1.5
2    1.0
相关问题