PyPy 是更快版本的python
PyPy3.7
后,就使用 pypy3 命令PyPy2.7
后,就使用 pypy2 命令conda create -n pypy_env
activate pypy_env
。可以看到虚拟环境目录(C:\Users\用户名\.conda\envs\pypy_env
)下只有了Scripts
和conda-meta
文件夹,内容也只有condaVC runtime library
. PyPy的官方下载页面,有提供它的安装链接然后安装pip工具.pypy3 -m ensurepip
之后安装包,就可以直接使用命令pypy3 -m pip install 包名
。
pypy3 -m pip install numpy
参考:
pypy3 -m pip install matplotlib==3.3.1
pypy3 -m pip install matplotlib==1.2.0
根据下面的两个测试,说明了
import time
t = time.time()
for i in range(10**8):
continue
print(time.time() - t)
测试结果,耗时:
import numpy as np
import time
t = time.time()
# row is y, column is x
row_count = 4024
col_count = row_count
center_x = col_count//2 - 0.5
center_y = row_count//2 - 0.5
x0 = np.arange(col_count)
y0 = np.arange(row_count)
x0 = x0 - center_x # 向右为正
y0 = center_y - y0 # 向上为正
x_grid, y_grid = np.meshgrid(x0, y0)
half_size = row_count / 2
x = x_grid.flatten() / half_size # 转换为 [-1,1]之间的值,单位圆嘛
y = y_grid.flatten() / half_size
x2 = x ** 2
y2 = y ** 2
x3 = x ** 3
y3 = y ** 3
x4 = x ** 4
y4 = y ** 4
xy = x * y
Z = np.zeros([15, len(x)])
# Z0
# Fun1 = lambda x, y: 1
Z[0, :] = np.ones_like(x)
# Z1
# Fun1 = lambda x, y: y
Z[1, :] = y
# Z2
# Fun2 = lambda x, y: x
Z[2, :] = x
# Z3
# Fun3 = lambda x, y: 2*x*y
Z[3, :] = 2 * xy
# Z4
# Fun4 = lambda x, y: -1 + 2 * (x ** 2 + y ** 2)
Z[4, :] = -1 + 2 * (x2 + y2)
# Z5
# Fun5 = lambda x, y: x**2 - y**2
Z[5, :] = x2 - y2
# Z6
# Fun6 = lambda x, y: 3 * x**2 * y - y**3
Z[6, :] = 3 * x2 * y - y3
# Z7
# Fun7 = lambda x, y: -2*y + 3*y * (x**2 + y**2) # 与效果图有点对不上
Z[7, :] = -2 * y + 3 * y * (x2 + y2)
# Z8
# Fun8 = lambda x, y: -2*x + 3*x * (x**2 + y**2) # 与效果图有点对不上
Z[8, :] = -2 * x + 3 * x * (x2 + y2)
# Z9
# Fun9 = lambda x, y: x**3 - 3*x*y**2
Z[9, :] = x3 - 3 * x * y2
# Z10
# Fun10 = lambda x, y: 4 * x**3 * y - 4 * x * y**3
Z[10, :] = 4 * x3 * y - 4 * x * y3
# Z11
# Fun11 = lambda x, y: -6*x*y + 8*x*y * (x**2 + y**2) # 与效果图有点对不上
Z[11, :] = -6 * xy + 8 * xy * (x2 + y2)
# Z12
# Fun12 = lambda x, y: 1 - 6*(x**2 + y**2) + 6*(x**2 + y**2)**2 # 与效果图有点对不上
Z[12, :] = 1 - 6 * (x2 + y2) + 6 * (x2 + y2)**2
# Z13
# Fun13 = lambda x, y: -3*x**2 + 3*y**2 + 4*x**4 - 4*y**4 # 与效果图有点对不上.我推出来,它的公式是对的,只是少了前面的系数根号10
Z[13, :] = -3 * x2 + 3*y2 + 4 * x4 - 4 * y4
# Z14
# Fun14 = lambda x, y: x**4 - 6 * x**2 * y**2 + y**4
Z[14, :] = x4 - 6 * x2 * y2 + y4
print(time.time() - t)
测试结果,耗时: