对我而言,最大的难题是几乎每个标准运算符都超载,无法在整个阵列中分布。
定义一个列表和一个数组
>>> l = range(10)>>> l[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> import numpy>>> a = numpy.array(l)>>> aarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
乘法复制python列表,但分布在numpy数组上
>>> l * 2[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> a * 2array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])
未在python列表上定义加法和除法
>>> l + 2Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: can only concatenate list (not "int") to list>>> a + 2array([ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])>>> l / 2.0Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: unsupported operand type(s) for /: 'list' and 'float'>>> a / 2.0array([ 0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5])
numpy重载有时将列表视为数组
>>> a + aarray([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])>>> a + larray([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])



