# 向量化代码

EOM = 0
for months in years:
PREM = 50
BOM = EOM + PREM
WIT = 5
EOM = BOM – WIT

import numpy as np
years = 10
bom = np.zeros(years*12)
eom = np.zeros(years*12)
for month in range(1, years*12):
prem = 50
bom[month] = eom[month-1] + prem
wit = 5
eom[month] = bom[month] - wit

import numpy as np
years = 10
prem = 50
wit = 5
eom = np.arange(years*12)*prem - np.arange(years*12)*wit
# 如果你仍希望将bom表作为数组：
bom = eom + np.arange(years*12)*wit

years = 10
prem = 50
wit = 5
result = [{'bom': 0, 'eom': 0}]
for month in range(1, years*12):
inner = {}
inner.update({'bom': result[month-1]['eom'] + prem})
inner.update({'eom': inner['bom'] - wit})
result.append(inner)

import numpy as np
import pandas as pd
years = 10
prem = 50
wit = 5
df = pd.DataFrame(data={'bom': np.zeros(years*12), 'eom': np.zeros(years*12)})
for i, row in df.iterrows():
if i > 0:
row.bom = df.loc[i-1, 'eom']
row.eom = row.bom - wit

Cython 和Numba

Numba也可以加速（它可能和Cython/Vectorized Numpy一样快）。在这两种情况下（Cython/Numba），你必须小心使用哪些数据类型（因为没有dicts或pandas！）。我认为，如果你对如何集成Cython+Numpy循环更聪明的话，它将有可能使Cython+Numpy循环与向量化Numpy一样快。

http://panchuang.net/

sklearn机器学习中文官方文档：
http://sklearn123.com/

http://docs.panchuang.net/