python matlab_适用于Matlab用户的python第1部分为什么python python vs matlab

python matlab

Maybe you’re an engineer like me who’s been using Matlab for quite some time and have grown super attached to it. You are probably fluent in the Matlab language, and whenever you face a problem you immediately start thinking in matrices and indexing notation.

也许您是像我这样的工程师,已经使用Matlab相当长一段时间了,并且对它的了解越来越深。 您可能精通Matlab语言,每当遇到问题时,您都会立即开始思考矩阵和索引符号。

You know that Python is 0-index’ed and already now you start questioning if such a language is really the way to go

您知道Python是0索引的,现在您已经开始质疑这种语言是否真的是正确的选择

But you can’t avoid listening when you hear engineers and data scientists talk about Python. How it’s one of the fastest, easiest languages to learn, and how it can do what Matlab can do — and much more. You then look at your most recent invoice from Mathworks and start questioning if a free-to-use programming language might actually be the way to go.

但是当您听到工程师和数据科学家谈论Python时,您就无法回避。 它是最快,最容易学习的语言之一,以及它如何完成Matlab可以做的事情-以及更多 。 然后,您查看来自Mathworks的最新发票,并开始质疑是否可以使用免费的编程语言。

But at the same time, you know that Python is 0-index’ed and already now you start questioning if such a language is really the way to go. Then you hear weird terms such as list comprehensions and you start to get slightly scared. You do a bit of searching around the internet and stumble over ugly, scary-looking code snippets such as the following:

但是与此同时,您知道Python是0索引的,现在您已经开始质疑这种语言是否真的可行。 然后,您会听到诸如列表理解之类的奇怪术语,并且开始感到有些害怕。 您需要在Internet上进行一些搜索,然后偶然发现难看的,看上去可怕的代码段,例如:

X = dict(zip(VarNames, [(np.array(data[name],dtype=float).flatten()) for name in VarNames] ) )

And now you start to wonder why anyone would use such a language.

现在您开始怀疑为什么有人会使用这种语言。

But you are stubborn. Just like me.

但是你很固执。 就像我。

And you know that just because you don’t quite understand what all the fuzz is about, you also know that so many people can’t be wrong. So you Google “Python for Matlab users” and now you’re here.

而且您知道,仅仅因为不太了解所有绒毛的含义,所以您还知道很多人不会错。 因此,您使用Google“ 面向Matlab用户的Python ”,现在您在这里。

So what is this? Well let me tell you:

那是什么 好吧,我告诉你:

In this blog series, I will explain how to transition from being a hardcore Matlab user, to becoming a Python fan.

在这个博客系列中,我将说明如何从成为Matlab的核心用户过渡到成为Python爱好者。

A word of caution though:

不过请注意:

This is not an expert’s guide to using Python. This is a beginner’s guide — as in I’m the beginner.

这不是使用Python的专家指南。 这是初学者的指南-因为我是初学者。

What this means for you is that I am writing this as I go, but after clearing up all the mistakes and dead ends I’ve taken, so you don’t have to repeat them. This writeup is therefore based on a lot of Googling around and plain and simple trial and error. But enough chatting — let’s start digging a bit deeper.

这对您来说意味着我正在写这篇文章,但是在清除了所有我遇到的错误和死胡同之后,您不必重复这些。 因此,本文是基于大量Google搜索以及简单明了的反复试验而得出的。 但是足够多的聊天-让我们开始更深入地探讨。

为什么是Python? (Why Python?)

The first step in using Python, is to actually decide to use it. There are many reasons why one might consider using Python, and I’ve listed the main ones for me in the following. Similarly, there are also good reasons why Matlab is superior to Python. These are also listed below.

使用Python的第一步是实际决定使用它。 人们可能会考虑使用Python的原因有很多,下面我列出了主要的原因。 同样,Matlab优于Python也有充分的理由。 这些也在下面列出。

An advantage of Python is the support for multiple IDEs meaning you can pick you own syntax highlighting. Photo by Chris Ried on Unsplash Python的优点是支持多个IDE,这意味着您可以选择自己的语法突出显示。 克里斯·里德 ( Chris Ried)在 Unsplash上 摄

Python比Matlab更好的10个理由 (10 Reasons Python is better than Matlab)

  1. It’s free.

    它是免费的

    This one is simple, but one of the most important ones for anyone working outside academia. As Matlab is an expensive software, many companies only have one (if any) license. For this reason, using a free alternative might be attractive for many companies.

    这很简单,但是对于在学术界以外工作的任何人来说,最重要的之一。 由于Matlab是一种昂贵的软件,因此许多公司仅拥有一个(如果有)许可证。 因此,对于许多公司而言,使用免费的替代品可能会很有吸引力。

  2. It’s open sourceHaving a language where everyone can contribute to the development of it means new features will constantly be added and bugs will be fixed. It also means you can go and inspect exactly how the functions you use works. This also aids in the growth of the language and helps making a big community of advanced users and contributors.

    它是开源的,拥有一种人人都能为它的开发做出贡献的语言,这意味着将不断添加新功能并修复错误。 这也意味着你可以去检查究竟是如何的功能使用的作品。 这也有助于语言的增长,并有助于建立一个由高级用户和贡献者组成的庞大社区。

  3. It’s the futureThe popularity of Python has just kept increasing in an exponential fashion over the past years. Having a more popular language means it’s easier to find answers to any questions you may have, and to find code examples of what you need.

    未来 ,在过去的几年中,Python的流行才以指数级增长。 使用一种更流行的语言意味着更容易找到您可能遇到的任何问题的答案,并找到您需要的代码示例。

  4. It has more featuresUnlike Matlab, Python is not just a scripting language for math — it’s also an imperative and function language which can be used for crawling web-servers, controlling external devices or making user interfaces.

    它具有更多功能与Matlab不同,Python不仅是数学的脚本语言,它还是一种命令式和函数式语言,可用于爬网Web服务器,控制外部设备或创建用户界面。

  5. It’s portablePython is, just like Matlab, a cross-platform, language which can run on al OSs — even embedded systems having a small Linux kernel. Deploying Python code is also easier — you just need to install python (which comes by default in many OSs) and not deal with having the right version of Matlab runtime. This also means it is super easy to deploy Python code to servers.

    就像Matlab一样, 它是可移植的 Python, 是一种跨平台的语言,可以在其他操作系统上运行,甚至可以在具有小型Linux内核的嵌入式系统上运行。 部署Python代码也更加容易-您只需要安装python(许多操作系统默认情况下安装),而无需处理具有正确版本的Matlab运行时。 这也意味着将Python代码部署到服务器非常容易。

  6. It’s THE go-to language for machine learningWith the increasing popularity of machine learning and AI, Python is light years ahead of Matlab, as all major frameworks are based on Python: Tensorflow, Keras, PyTorch, Scikit-learn. And since all AI research is made using these frameworks it is way easier to find state of the art algorithms for Python than Matlab.

    它是机器学习的首选语言随着机器学习和AI的日益普及,Python领先于Matlab,因为所有主要框架均基于Python:Tensorflow,Keras,PyTorch和Scikit-learn。 而且由于所有AI研究都是使用这些框架进行的,因此与Matlab相比,找到最先进的Python算法更容易。

  7. It’s highly flexibleIn Python, there are many ways to achieve the same functionality. Some are of course more efficient than others, but having a language which allows you to do things the way that suits you is highly appreciated.

    它具有高度的灵活性在Python中,有很多方法可以实现相同的功能。 当然,有些语言比其他语言更有效,但是拥有使您能够以适合自己的方式进行操作的语言受到高度赞赏。

  8. It allows for using different IDEsWhen using Matlab you’re forced to use the Matlab IDE shown in the image below. Luckily the Matlab IDE works quite well, but you are also quite limited to the features that Matlab has chosen to implement: For instance is Git support quite poor. As Python can be compiled from the command-line many different IDEs are available — from simple text editors to full-fledged Matlab-like solutions.

    它允许使用不同的IDE 。使用Matlab时,您必须使用下图所示的Matlab IDE。 幸运的是,Matlab IDE可以很好地运行,但是您也仅限于Matlab选择实现的功能:例如,Git支持非常差。 由于可以从命令行编译Python,因此可以使用许多不同的IDE,从简单的文本编辑器到成熟的Matlab类解决方案。

  9. Simpler (prettier) languageEven though it might not appear so at first sight, Python can actually produce much simpler, and thus prettier, code than Matlab. One such example is in for-loops where you can get both the index i and i’th item when iterating over an array.

    更简单(更漂亮)的语言尽管乍看之下可能看起来并不像Python,但实际上它可以比Matlab产生更简单,更漂亮的代码。 一个这样的示例在for循环中,在数组上进行迭代时,您可以同时获得索引i和第i个项。

  10. Named argumentsNamed arguments in Python lets you call a function ala. mean(X, axis=1), where you in Matlab would write mean(X,1) i.e. it would be unclear what the 1 is used for. This makes the code much easier to read and debug.

    命名参数 Python中的命名参数使您可以调用函数ala。 mean(X,axis = 1),在Matlab中您将在其中写入mean(X,1),即不清楚1的用途。 这使代码更易于阅读和调试。

Wikipedia 维基百科的照片

Matlab比Python更好的10个理由 (10 Reasons Matlab is better than Python)

  1. It “just works”Since Matlab is closed-source they also guarantee that when you install it, all the necessary bits (no pun intended) and pieces are there for Matlab to run successfully. This is not guaranteed in Python. Fortunately, I am here to help and have made a guide on how to install Python.

    它“有效”,因为Matlab是开源的,他们还保证在安装Matlab时,所有必要的位(没有双关语)和零件都可以使Matlab成功运行。 在Python中无法保证。 幸运的是,我在这里为您提供帮助,并为如何安装Python提供了指南 。

  2. There’s a big company behind itSince Matlab is made by Mathworks, they also guarantee the quality and correctness of their product (that’s what you’re paying for if you are in doubt!). It also means there’s a support team to write to should you have any problems with their product.

    背后有一家大公司由于Matlab由Mathworks制造,因此它们还保证其产品的质量和正确性( 如果您有疑问,这就是您要付出的代价! )。 这也意味着,如果您对他们的产品有任何疑问,可以给您提供支持小组。

  3. Simulink

    Simulink

    Depending on your field of engineering, you may or may not use Simulink. For some, it is an absolutely must-have, whereas others (myself included) have barely opened it.

    根据您的工程领域,您可能会或可能不会使用Simulink。 对于某些人来说,这是绝对必须的,而其他人(包括我自己)几乎没有打开它。

  4. Toolboxes

    工具箱

    This again depends on your field of engineering, but communications engineers, having the LTE toolbox makes life much easier, while the optimal control toolbox and system identification toolboxes are hard to live without for most control engineers.

    这又取决于您的工程领域,但是拥有LTE工具箱的通信工程师可以使工作变得更加轻松,而对于大多数控制工程师而言,没有最佳的控制工具箱和系统标识工具箱是很难的。

  5. It executes fasterThis point might open up for a great deal of debate, but my impression is that Matlab code by default executes faster than Python, simply because many Matlab functions are pre-compiled by default, while the user has to do this manually in Python.

    它执行速度更快这一点可能引发很多争论,但是我的印象是Matlab代码默认情况下的执行速度比Python要快,这仅仅是因为许多Matlab函数默认情况下是预编译的,而用户则必须手动执行此操作。Python。

  6. Better debugging

    更好的调试

    The Matlab debugger is amazing: The ability to click to insert a breakpoint in a sub-function and then inspect all the functions’ variables (including variables of higher-level functions, by changing the call stack) is a super powerful tool . Python also has a debugger, but it’s way more complicated to get to work, and is by no means as simple as the Matlab debugger and it honestly just doesn’t work as well.

    Matlab调试器令人惊叹:能够单击以在子函数中插入断点,然后检查所有函数的变量(包括通过更改调用堆栈来更改更高级别函数的变量)的能力非常强大。 Python也有一个调试器,但是它的工作方式更加复杂,并且绝非Matlab调试器那么简单,说实话,它也不起作用。

  7. No packages to include/manage

    没有要包含/管理的软件包

    Since Matlab installs as a full program, all the necessary libraries are included in the installation. This means once they are installed there is no need to remember to include the various toolboxes to use their functionalities — they just work.

    由于Matlab是作为完整程序安装的,因此所有必需的库都包含在安装中。 这意味着,一旦安装它们,就无需记住要包括各种工具箱来使用其功能-它们就可以工作。

  8. You already know how to use itThis is probably the strongest argument for Matlab, and the hardest one to combat. There is just no way of beating +10 years of experience using a certain language — no matter how clever the alternatives might be.

    您已经知道如何使用它。这可能是Matlab的最强论据,也是最难解决的论据。 无论使用哪种语言,都无法击败使用某种语言的10年以上的经验。

  9. Your entire code-base is using itJust as there is no way of beating +10 years of coding experience, there is also no way of beating +10 years of scripts, functions and those driver functions you wrote which you keep using on a day-to-day basis. And let’s be honest: You don’t have the time, nor desire to port them to Python.

    您的整个代码库都在使用它,就像无法击败+10年的编码经验一样,也无法击败+10年的脚本,函数以及您每天使用的驱动程序函数每天 老实说:您没有时间,也不想将它们移植到Python。

  10. Your peers are using itAnd finally, another argument which is hard to do anything about: If he entire scientific community in your field (or company) are using Matlab, then you’ll undoubtedly be sharing Matlab code back and forth. Unless you become that guy who uses Python. But you want to be in the inner circle with all the other Matlab nerds. Ahh, if only everyone else was using it, it would be much simpler to make the switch. But someone has to be the front-runners in this world! Why not you?

    你的同龄人都在使用它 。最后,另一种说法是很难做到的任何事情:如果在你的领域(或公司),他整个科学界都采用Matlab,那么你无疑会分享Matlab代码来回。 除非您成为使用Python的 那个人 。 但是您想和所有其他Matlab书呆子一起处于圈内。 嗯,如果只有其他人都在使用它,则进行切换会容易得多。 但是有人必须成为这个世界的领跑者! 为什么不是你?

If only everyone else was using it, it would be much simper to make the switch

如果只有其他人都在使用它,那么进行切换将非常简单。

I can’t tell you which of the advantages outweigh the others — that depends entirely on the context and the situation of each individual Matlab user. To me, many of the reasons to stick with Matlab are related to the momentum gained by having used Matlab for years and feeling “at home” with the software. And being afraid of taking the leap and putting in the work.

我无法告诉您哪些优势胜过其他优势-完全取决于每个Matlab用户的环境和情况。 对我而言,坚持使用Matlab的许多原因与使用Matlab多年并使用该软件感到“宾至如归”有关。 并害怕飞跃并投入工作。

But, if this read hasn’t entirely thrown you off and you are motivated to give Python a try, let’s continue to the next part where we actually install Python!

但是,如果这种读法还没有完全使您失望,并且您有动力尝试使用Python,那么让我们继续 下一个我们实际安装Python的部分

翻译自: https://medium.com/@rasmusgs/python-for-matlab-users-part-1-why-python-python-vs-matlab-959d92d702ef

python matlab

你可能感兴趣的:(python)