68
$\begingroup$

First of all, I'm a beginner studying AI and this is not an opinion-oriented question or one to compare programming languages. I'm not implying that Python is the best language. But the fact is that most of the famous AI frameworks have primary support for Python. They can even be multilanguage supported, for example, TensorFlow that supports Python, C++, or CNTK from Microsoft that supports C# and C++, but the most used is Python (I mean more documentation, examples, bigger community, support, etc). Even if you choose C# (developed by Microsoft and my primary programming language), you must have the Python environment set up.

I read in other forums that Python is preferred for AI because the code is simplified and cleaner, good for fast prototyping.

I was watching a movie with AI thematics (Ex Machina). In some scenes, the main character hacks the interface of the house automation. Guess which language was on the scene? Python.

So, what is the big deal with Python? Why is there a growing association between Python and AI?

$\endgroup$
1
  • 2
    $\begingroup$ Just bear in mind that the representation of programming languages in movies is not usually related to real life! Anything that looks like cryptic gobbledegook to lay people is usually fine... $\endgroup$ Commented May 23, 2018 at 10:33

10 Answers 10

48
$\begingroup$

Python comes with a huge amount of inbuilt libraries. Many of the libraries are for Artificial Intelligence and Machine Learning. Some of the libraries are TensorFlow (which is a high-level neural network library), scikit-learn (for data mining, data analysis and machine learning), pylearn2 (more flexible than scikit-learn), etc. The list keeps going and never ends. You can find some libraries here.

Python has an easy implementation for OpenCV. What makes Python favorite for everyone is its powerful and easy implementation.

For other languages, students and researchers need to get to know the language before getting into ML or AI with that language. This is not the case with Python. Even a programmer with very basic knowledge can easily handle Python. Apart from that, the time someone spends on writing and debugging code in Python is way less when compared to C, C++ or Java. This is exactly what the students of AI and ML want. They don't want to spend time on debugging the code for syntax errors, they want to spend more time on their algorithms and heuristics related to AI and ML

Not just the libraries but their tutorials, handling of interfaces are easily available online. People build their own libraries and upload them on GitHub or elsewhere to be used by others.

All these features make Python suitable for them.

$\endgroup$
3
  • 22
    $\begingroup$ "They don't want to spend time on debugging the code for syntax errors" - Does any programmer want to do this? Is Python the best languge for everything? I am not convinced. $\endgroup$ Commented Feb 7, 2019 at 19:19
  • 3
    $\begingroup$ Endless trade offs in all these areas: what python has in simplicity/built in libraries it can lose in stuff like speed, memory usage etc. Somewhat like vehicles - a simple automatic car is easy to learn to drive with and get around a city but won't get you very far in a race vs a race car, plane or an aircraft carrier. Can only try and pick the best tool for the problem. $\endgroup$
    – Philip
    Commented Nov 11, 2019 at 15:17
  • $\begingroup$ Python is without doubt a rapid language to prototype code in, but it may be said that i is a slow language to deliver in. It lacks support for programming in the large, but most 'AI' programming is akin to saying you are doing operating system development by writing a Windows GUI. Look at the documentation for setting up the file structure for a full project docs.python-guide.org/writing/structure. It doesn't support multicore CPUs as it lacks modern multithreading. So you buy an expensive 8 core PC, use 1 core with code that runs 10 times slower than the same in a compiled language. $\endgroup$
    – Nick
    Commented Jan 29, 2021 at 14:20
35
$\begingroup$

Practically all of the most popular and widely used deep-learning frameworks are implemented in Python on the surface and C/C++ under the hood.

I think the main reason is that Python is widely used in scientific and research communities, because it's easy to experiment with new ideas and code prototypes quickly in a language with minimal syntax like Python.

Moreover there may be another reason. As I can see, most of the over-hyped online courses on AI are pushing Python because it is easy for newbie programmers. AI is the new marketing hot word to sell programming courses. ( Mentioning AI can sell programming courses to kids who want to build HAL 3000, but can not even write a Hello World or drop a trend-line onto an Excel graph. :)

$\endgroup$
4
  • 5
    $\begingroup$ ".......most of the over-hyped online courses on AI are pushing Python because it is easy for newbie programmers. AI is the new marketing hot word to sell programming courses..." ---- Good point. Cant agree more. $\endgroup$ Commented Mar 4, 2019 at 19:40
  • $\begingroup$ I agree on the point that seeing AI topic everywhere while non-AI problem not solved $\endgroup$
    – Nam G VU
    Commented May 2, 2021 at 16:13
  • $\begingroup$ because it's easy for newbie programmers, really? Not because of all the AI libraries they want to use? $\endgroup$ Commented Aug 31, 2021 at 10:50
  • 2
    $\begingroup$ @user253751 That's exactly what I wrote in the first sentence: "Practically all of the most popular and widely used deep-learning frameworks are implemented in Python" $\endgroup$
    – user6933
    Commented Sep 2, 2021 at 6:31
9
$\begingroup$

What attracts me to Python for my analysis work is the "full-stack" of tools that are available by virtue of being designed as a general purpose language vs. R as a domain specific language. The actual data analysis is only part of the story, and Python has rich tools and a clean full-featured language to get from the beginning to the end in a single language (use of C/Fortran wrappers notwithstanding).

On the front end, my work commonly starts with getting data from a variety of sources, including databases, files in various formats, or web scraping. Python support for this is good and most database or common data formats have a solid, well-maintained library available for the interface. R seems to share a general richness for data I/O, though for FITS the R package appears not to be under active development (no release of FITSio in 2.5 years?). A lot of the next stage of work typically occurs in the stage of organizing the data and doing pipeline-based processing with a lot of system-level interactions.

On the back end, you need to be able present large data sets in a tangible way, and for me, this commonly means generating web pages. For two projects I wrote significant Django web apps for inspecting the results of large Chandra survey projects. This included a lot of scraping (multiwavelength catalogs) and so forth. These were just used internally for navigating the data set and helping in source catalog generation, but they were invaluable in the overall project.

Moving to the astronomy-specific functionality for analysis, it seems clear that the community is solidly behind Python. This is seen in the depth of available packages and level of development activity, both at an individual and institutional level (http://www.astropython.org/resources). Given this level of infrastructure that is available and in work, I think it makes sense to direct effort to port the most useful R statistical tools for astronomy to Python. This would complement the current capability to call R functions from Python via rpy2.If you are interested, I strongly recommend that you read this article, here it is a question of comparing programming languages https://diceus.com/what-technology-is-b ... nd-java-r/ I hope it helps.Good Luck

$\endgroup$
1
  • $\begingroup$ Thanks for sharing. I would love if we have the summary on top and then full detail as yours after that. $\endgroup$
    – Nam G VU
    Commented May 3, 2021 at 3:26
8
$\begingroup$

Python has a standard library in development, and a few for AI. It has an intuitive syntax, basic control flow, and data structures. It also supports interpretive run-time, without standard compiler languages. This makes Python especially useful for prototyping algorithms for AI.

$\endgroup$
1
  • 1
    $\begingroup$ Nice point about the interpretive capability of Python. It seems like flexibility and development speed is strongly favored over the greater "horsepower" of compiled languages. $\endgroup$
    – DukeZhou
    Commented Jun 15, 2017 at 15:40
4
$\begingroup$

It's a mix of many factors that together make it a very good option to develop cognitive systems.

  • Quick development
  • Rapid prototyping
  • Friendly syntax with almost human-level readability
  • Diverse standard library and multi-paradigm
  • It can be used as a frontend for performant backends written in compiled languages such as C/C++.

Existing performant numerical libraries, such as numpy and others already do the intensive bulk work for you which lets you focus more on architectural aspects of your system.

Besides, there is a very big community and ecosystem around Python, which results in a diverse set of available tools oriented to diffent kind of tasks.

$\endgroup$
3
$\begingroup$

That’s because python is a modern scripting object-oriented programming language that has stylish syntax. Contrary to structural programming languages like java and C++, its scripting nature enables the programmer to test his/her hypothesis very fast. Furthermore, there are lots of open source machine learning libraries (including scikit-learn and Keras) that broaden the use of python in AI field.

$\endgroup$
3
$\begingroup$

Python has rich library, it is also object oriented, easy to program. It can be also used as frontend language. That's why it is used in artificial intelligence. Rather than AI it is also used in machine learning, soft computing, NLP programming and also used as web scripting or in Ethical hacking.

$\endgroup$
0
1
$\begingroup$

We also work with Python in our company. One of the sphere that we use it for is fast prototyping and building highly scalable web applications. For over two decades, our Python developers have been providing businesses with full-stack web-development services, client-server programming and administration. We help our clients build high-load web portals, automation plugins, high-performance data-driven enterprise systems, and many more.

$\endgroup$
1
$\begingroup$

I actually prefer C for machine learning. Because like in life, in the world as we know it, consists of never-ending "logic gates" (which basically is like flipping a coin - there WILL be 2 possible outcomes - not counting the third: landing on the side!). Which also means that while the universe seems never-ending, we still never stop finding those things that are even smaller than the last smallest thing, right?

So... To put it in a context when programming C, I can control the memory usage more efficiently by coding smaller snippets that get combined, to always form smaller & efficient "code-fragments", that make up what we would call "cells" in biology (it got a measurable function, and has some pre-set properties).

Thus, I like to optimize for low RAM usage, low CPU usage etc. when programming AI. I have only done feedforward with a basic genetic algorithm in C, but the more advanced recurrent neural network I wrote in C++ (ONLY because of the simplicity of using std::vector<TYPE> name;, so I wrote my own cvector.c: https://pastebin.com/sBbxmu9T & cvector.h: https://pastebin.com/Rd8B7mK4 & debug: https://pastebin.com/kcGD8Fzf - compile with gcc -o debug debug.c cvector.c). That actually helped a lot in the quest of optimizing CPU usage (and overall runtime) when creating optimized neural networks.

EDIT: So I am in one sense really see the opposite of what AlexPnt sees, when it comes to exploring what is possible within the realm of a "self".

$\endgroup$
1
$\begingroup$

Many people who are interested in machine learning aren't professional programmers. For example there are mathematicians who work on differential equations and there are physicists who work on stochastic processes. These people aren't programmers. So using a language like C++ which is hard to learn is only detrimental to their works. And also creating a model in Python is much easier compared with C++ and Java. You have to use C++ when you want to create a game engine because the graphics is directly related to the hardware and if you want to be a professional Android programmer you have to learn Java. What are the benefits of choosing C++ and Java over Python when your work mainly consists of linear algebra and statistics?

$\endgroup$
1
  • $\begingroup$ You make clear sense! That's what Google see and invest into library in python to provide to those non-pro coding scientist $\endgroup$
    – Nam G VU
    Commented May 3, 2021 at 3:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .