获取数组中单个元素时,使用item()会比下标语法更快一些,但是仍然比列表慢:

1>>> a = np.random.rand(10)
2>>> %timeit a[2]
31000000 loops, best of 3: 207 ns per loop
4>>> %timeit a.item(2)
510000000 loops, best of 3: 175 ns per loop
6>>> b = [0.1, 0.2, 0.3]
7>>> %timeit b[2]
810000000 loops, best of 3: 79.3 ns per loop