numpy函数向量化,np.vectorize
2021-03-12 17:29
106 查看
import numpy as np import time def myfunc(a, b): if a>b: return a-b else: return a+b vfunc = np.vectorize(myfunc) t0=time.time() vfunc(np.random.randint(5,size=10000000), 2) t1=time.time() print('speed_times:'+str(t1-t0)) #speed_times:3.2735631465911865 t0=time.time() [myfunc(data, 2) for data in np.random.randint(5,size=10000000)] t1=time.time() print('speed_times:'+str(t1-t0))
结果:向量化后的并行运算速度要比普通的执行速度快很多
speed_times:2.7337491512298584
speed_times:9.00490427017212
相关文章推荐
- np.vectorize()和crosstab()和pivotTab()函数解释
- Python Intro - Numpy function vectorize
- numpy函数之np.maximum
- 孤立词语音识别之Vector Quantization(矢量量化)
- python-numpy.vectorize()
- LVQ,Learning Vector Quantization,学习向量量化
- numpy函数:np.arange(24)reshape(4,3,2)用法
- C实现的类似vector的容器
- vector第二步修炼之道
- -bash: /usr/bin/phpize
- C++自带向量_vector_C++
- 机器学习之支持向量机SVM Support Vector Machine (一) 线性SVM模型与软硬间隔
- 记录一个vector陷阱
- Vector和ArrayList的比较
- java中Vector的实现
- 合并两个vector
- vector
- 机器学习之支持向量机SVM Support Vector Machine (四) SMO算法
- nyoj-20--吝啬的国度-DFS+vector
- C语言vector的使用方法 C++中vector的用法详解