How to convert multiple matrices into one single vector in Python?

By | 2017-04-24T20:38:51+00:00 April 24th, 2017|languages, python|

This is a quick post on how to convert multiple matrices into a single vector using Python's numpy package. To begin with let us define 2 matrices. [crayon-59c7b84991b31999006406/] What we want to do is to merge the contents of mat1 and mat2 into a single vector. To reach that goal first we need to convert each of them into vectors. For this we will make use of Numpy's reshape. [crayon-59c7b84991b46528061727/] The -1 value for the newshape parameter of reshape ensures that the output has only 1 dimension. A matrix with 1 dimension is called a vector, which is what we want to achieve. Now that we have flattened both the matrices, we can merge (concatenate) [...]

Using PyCharm with Anaconda Virtual Environments

By | 2017-04-15T20:37:34+00:00 April 19th, 2017|Linux, operating systems, python, tools|

If you are regular reader of my blog, you would have noticed that I use Python mostly in Anaconda virtual environments. PyCharm is my favourite IDE for Python. Now the question is does PyCharm support conda environments? Fortunately the answer is Yes! In this post I will walk through the settings in PyCharm so that you can chose the right conda environment. Launch PyCharm and navigate to Settings --> Project Interpreter. If you click on the dropdown arrow, it should list all the interpreters currently available on the system which also includes interpreters from conda environments. If for some reasons you don't see the desired interpreter [...]

Finding the dot product in Python without using Numpy

By | 2017-04-18T12:16:20+00:00 April 18th, 2017|machine learning, python|

In Deep Learning one of the most common operation that is usually done is finding the dot product of vectors. In very simple terms dot product is a way of finding the product of the summation of two vectors and the output will be a single vector. This Wikipedia article has more details on dot products. The following formula should make it clear where $latex \vec{X}&s=1$ and $latex \vec{Y}&s=1$ are vectors. $latex \vec{X}=(x_1,x_2...x_n)&s=1$ $latex \vec{Y}=(y_1,y_2...y_n)&s=1$ then the dot product formula will be $latex \vec{X}.\vec{Y}=(x_1y_1+x_2y_2+...+x_ny_n)&s=1$ Here is an example of dot product of 2 vectors. $latex \vec{X}=(6,5,4)\vec    {Y}=(3,2,1)&s=1$ so $latex \vec{X}&s=1$  dot $latex \vec{Y}&s=1$ will be $latex \vec{X}.\vec{Y}=(6*3+5*2+4*1) = 32&s=1$ Finding the dot [...]

How to install PyCharm on Ubuntu

By | 2017-04-15T12:39:01+00:00 April 17th, 2017|languages, python, tools|

Pycharm is my favorite IDE for Python especially its feature rich debugger. This is a quick post where will be installing PyCharm on Ubuntu. Let's first download PyCharm Community Edition installer to the desired location where we want to have PyCharm installed. I had chosen ~/pycharm folder. Next we will extract the archive using the following command [crayon-59c7b8499ab8e189862510/] In the terminal navigate to the folder where the pycharm.sh file is located, in my case /home/pradeep/pycharm/pycharm-community-2017.1.1/bin. Then execute the following command in the following terminal. [crayon-59c7b8499ab9d935044748/] If you just execute pycharm.sh you may encounter "command not found error". So make sure to enter the command with the "./" along with [...]

How to reduce the size of a bloated Jupyter Notebook

By | 2017-04-10T19:47:34+00:00 April 13th, 2017|languages, python, tools|

I was recently working on a Python project using Jupyter Notebook. The data that I was dealing with was relatively large and the training iteration was also high. As and when I executed the code in Jupyter Notebook, its size started to increase drastically. This is because the Notebook by default saves the output of the code as well. Finally when I wanted to share the notebook, I realized that the file had grown to 100 MB in size! I had also closed the Notebook abruptly while the Kernel was still executing some code. As a result whenever I tried to open the notebook, the browser would [...]

Managing environments with CONDA

By | 2017-03-29T16:23:52+00:00 April 1st, 2017|languages, python|

In my previous post we installed Anaconda and configured it. Anaconda is very useful to work in Python in a various virtual environments which are completely isolated from each other. In this post we will look into some of the commands which are useful for managing those virtual environments. Create a Virtual Environment Executing the following command creates a virtual environment named newenv with Python version 2.7 [crayon-59c7b8499c99d925479066/] List the environments currently created Any of the following commands will give us the list of environments that are already created. [crayon-59c7b8499c9ab350788102/] [crayon-59c7b8499c9b3579045918/] Export active environment to a file Consider this. I have created an environment ,installed [...]

Install and configure Jupyter (IPython) notebook on Ubuntu

By | 2017-03-26T21:56:04+00:00 March 31st, 2017|languages, Linux, operating systems, python|

Jupyter notebooks are the best thing that had happened to Python development in the recent past. These notebooks contain  ready to publish code and documentation. Easy to share, collaborate is one of the key aspects of Jupyter notebooks. The more you use it the more you will like it. In this post I will quickly walk you through the installation and configuration of Jupyter/IPython notebook on Ubuntu. We will do the package installation through Anaconda. [crayon-59c7b8499fb21994469937/] The above command will install Jupyter notebook (note the space between jupyter and notebook). Once the package is successfully installed, just execute the following command to open the Jupyter [...]

Installation and configuration of Anaconda on Ubuntu

By | 2017-03-26T19:56:46+00:00 March 30th, 2017|languages, Linux, machine learning, operating systems, python|

This is a quick post on how to install/configure Anaconda on Ubuntu. We will also create virtual environments using Anaconda. What is Anaconda? Anaconda is a package manager for Python which makes it easy to install and configure packages which are usually used for Data Science related work using Python. As we did using virtualenv package, we can also create virtual environments using Anaconda. This helps us to work on multiple projects using various versions of packages completely isolated, all in a single computer. Installing Anaconda Anaconda can be downloaded from here. The installer is ~500 MB in size. Once downloaded, execute the following command [...]

The step by step guide to install TensorFlow on Windows

By | 2017-03-27T06:13:11+00:00 March 28th, 2017|languages, machine learning, operating systems, python, TensorFlow, Windows|

In the previous post we had installed TensorFlow in a virtualised environment on Ubuntu 16.04. In this post we will install TensorFlow on Windows 10 including all the pre-requisites. Since I have a laptop with NVIDIA GPU, I will install TensorFlow with GPU support. NVIDIA CUDA First of all we will install NVIDIA CUDA on Windows as installing TensorFlow with GPU support is recommended. We will download NIVIDIA CUDA from here. The installation is very straight forward, a few clicks and the installation is complete. Install Python 3.5 Once the CUDA installation is complete, initiate a reboot of the workstation. Then we need to install Python. On Windows TensorFlow supports versions 3.5.x versions [...]

How to install TensorFlow with GPU support using Python Virtualenv

By | 2017-03-26T19:59:36+00:00 March 27th, 2017|languages, Linux, machine learning, python, TensorFlow|

In this post I will install TensorFlow with GPU support using Virtualenv. I will be installing this on Ubuntu 16.04 however the steps will remain the same for other operating systems as well. Before we install TensorFlow please make sure that the following prerequisites are taken care of. Install NVIDIA CUDA (this if for GPU support) Install Virtualenv package on Python. The installation is pretty straight forward. First we need to create the Virtual environment using the following command [crayon-59c7b849a89d1249719892/] During the installation of virtualenv I had created a folder named myvirtualenv under my home directory. Hence I used that folder in the above command. [...]