Vectorization in Python

栏目: IT技术 · 发布时间: 5年前

内容简介:Python is a popular language for Data Science. With it’s easy to learn (and read) syntax it makes getting up and running with the language much more accessible for newbies. However, without getting into the details, Python is anWhen we perform Deep Learnin

PyTrix#1: Speeding up our Python Code

May 7 ·4min read

Python is a popular language for Data Science. With it’s easy to learn (and read) syntax it makes getting up and running with the language much more accessible for newbies. However, without getting into the details, Python is an interpreted language which means it runs much slower than a compiled language , like C.

When we perform Deep Learning it’s likely we are using large amounts of data because that is when Deep Learning thrives.

Vectorization in Python

Figure 1: Photo from Andrew Ng Deep Learning Specialization on Coursera

Why am I saying all of this? Great question!

If we have large amounts of data and slow python code, we are more than likely going to end up with a model that runs at snails pace because our code is not computationally optimal... What was man’s solution to this great disaster? Vectorization! B-)

What is Vectorization?

To put it in layman’s terms, It speeds up Python code without the need for looping, indexing, etc., and in Data Science we use Numpy to do this — Numpy is the de facto framework for scientific programming. Technically, we still perform these operations when we implement the vectorized form in Numpy, but just not in Python — under the hood. Instead, the operations are done in optimised, pre-compiled C code — see the Documentation for more information on this.

“This practice of replacing explicit loops with array expressions is commonly referred to as vectorisation. In general, vectorized array operations will often be one or two (or more) orders of magnitude faster than their pure python equivalents, with the biggest impact seen in any kind of numerical computations” — McKinney, 2012, p. 97

以上所述就是小编给大家介绍的《Vectorization in Python》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

结构化计算机组成

结构化计算机组成

Andrew S.Tanenbaum / 刘卫东 / 机械工业出版社 / 2001-10-1 / 46.00

AndrewcS.Tanenbaum获得过美国麻省理工学院的理学学士学位和加利福尼亚大学伯克利分校的哲学博士学位,目前是荷兰阿姆斯特丹Vrije大学计算机科学系的教授,并领导着一个计算机系统的研究小组.同时,他还是一所计算与图像处理学院的院长,这是由几所大学合作成立的研究生院.尽管社会工作很多,但他并没有中断学术研究. 多年来,他在编译技术.操作系统.网络及局域分布式系统方面进行了大量的一起来看看 《结构化计算机组成》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试