Files

Python Tutorials

Hey! So you want to learn Python? Good 👍 you are at the right place! 😄

Here is what you have to know:

  • There are mainly 2 versions of Python: Python 2 and Python 3. The most known version of the former is Python 2.7, and is currently installed by default on Linux and MacOSX systems. You can try it by typing python in the terminal. To exit, push Ctrl+D or type exit(). Note that Python 2.7 will stop to be maintained in 2020. Now, I am pretty sure that you are asking yourself "what is the difference between Python 2.7 and Python 3?". Well, to be short "Python 2.x is legacy, Python 3.x is the present and future of the language" as mentioned here. However, if you are using ROS/Gazebo, I would still recommend to use Python 2.7 for now. Pratically, these 2 versions are similar except for few details, the print statements where you don't have to put parenthesis in Python 2.7, and for few specific libraries. Personally, most of my code works in Python 3 and Python 2.7.

  • Check first this "Tutorial: Learn Python in 10 Minutes" to get a general understanding of the language. It assumes that you already know at least one programming language such as C++, Java or Matlab. Otherwise, it will take you more than 10minutes 😜

  • Then check this one for Python 2.7 or this one for Python 3.

  • Well now, you just have to practice! 😁

About Libraries/Modules

The libraries (aka modules) that are useful for roboticists and/or machine learning engineers are:

  • numpy for vectors, matrices, and tensors. Here is the tutorial.
  • matplotlib for plotting.
    • check here to see the gallery (basically it shows you what you can do with it).
    • check this tutorial to learn on how to use it. The first link Pyplot tutorial should be enough to have a basic understanding.
  • scipy for scientific and mathematical tools such as optimization, interpolation, signal processing, etc. You can find the tutorials at the following link.
    • If you are not satisfied with scipy.optimize.minimize, you can have a look at cvxpy (which uses different solvers such as cvxopt) for convex optimization. For QP problems with cvxopt, you can have a look at this small tutorial. For general nonlinear optimization, you can check nlopt, or ipopt with the corresponding documentation. Most of these softwares are written in C/C++/Fortran but provides python wrappers to call the various functions.
  • sklearn for machine learning algorithms. You can have a look at this library with the tutorials and documentations at the following link.
  • pandas when working with tables and data structures. It also provides you data analysis tools. Check here for a "10min" tutorial.

More specific libraries:

  • Deep Learning (or if you want to work with Tensors, or use automatic derivation tools)
    • TensorFlow (aka TF) which can be found here.
    • PyTorch at the following webpage.
      • Difference between PyTorch and TF? You can have a look at this blog and this medium post. Quickly, TF is being developed by Google, is more stable, has a bigger community, deals very nicely with the hardware part, has a syntax close to numpy, and is the current tool to use if you want to develop a software product. Meanwhile, PyTorch has a better integration with Python, allows you to use dynamic graphs (instead of static ones as in TF) and experiment new ideas faster. Hovewer, it is still in its early phase and the syntax used is currently different from numpy.
    • Keras: this library is in the process of being integrated into TensorFlow. Quick description: it provides higher functionalities and is used on top of Theano or TensorFlow.
    • Theano: this library is no longer maintained.
  • Gaussian Processes
    • GPy: the repo can be found here. Note that sklearn also allows you to use basic GPs but it is not as complete as GPy. For tutorials, have a look here
  • Reinforcement Learning
    • RL Environments
      • OpenAI-Gym: the repo is here, the documentation can be found here, and the environments are here.
  • Dynamic Movement Primitives
    • pydmps: the repo can be found here and the tutorials (which are very nice) are on this blog.
  • rospy: this library allows you to use ROS (the Robot Operating System). Check here and here for the tutorials.

C/C++ libraries with Python support:

  • OpenCV: library for computer vision.
  • KDL: kinematics and dynamics library.
  • RBDL: rigid body dynamics library.

Nice tools

Here are nice tools that you should know:

  • Jupyter Notebook. As mentioned on their webpage, "The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text".
  • pip which is tool that allows you to install Python packages/modules/libraries. For instance, to install numpy you would type in the terminal: pip install numpy.
  • Anaconda which allows you to create virtual environments and install packages like pip.
  • Cython: this one is not really a tool, but allows you to wrap C/C++ classes and functions, and use them in Python. You could also use it to write Cython code which would be faster than pure Python code. Having said that, it takes quite a bit of time to learn this language, and effectively use it.

For Matlab Users

So you want to move from Matlab? Good, you are definitely at the right place 😉 Here are few webpages that could be useful for you:

  • The following link explains the difference between Matlab and Python. I would also add that Python has a bigger community (because it is free), and is becoming the programming language to use for machine learning.
  • Numpy for Matlab Users: Link1 and Link2.

That's all folks! 👏