## PowerShell keep printing 1 before expected output

By | 2017-05-15T10:26:40+00:00 May 15th, 2017|languages, Scripts|

I had written a script to parse the contents of a URL and store the contents in a SQL Server table. The script has a couple of write-host commandlets to track the progress of the script. Here is a snippet of the script. [crayon-59788da282bb0248815884/] However on executing the script, before the write-host commandlet a couple of "1" would be written in the console. I had nowhere written in the script to write "1" to the console! On having a closer look, I realized that the SqlCommand.ExecuteNonQuery method was the culprit. Here is why. As per the documentation, the return value of SqlCommand.ExecuteNonQuery method will always be the number of [...]

## 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-59788da28549e523543648/] 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-59788da2854b0054270884/] 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-59788da286dfe317050437/] 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-59788da286e0d772029721/] 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 [...]

## AutoHotKey | Script fails with variable name contains an illegal character

By | 2017-04-05T17:56:28+00:00 April 5th, 2017|Scripts, tools|

I am a big fan of automating routine tasks. When I work on Windows AutoHotKey scripting language is my go-to tool for automation. With AutoHotKey one can automate just about anything on Windows. While working on one such scripts, I encountered the following problem. [crayon-59788da28964b974945974/] As seen in the above error message, in line 14 I am splitting a variable with text values (delimited by ".") and assigning the output to an array called word_array. Now the script is complaining that the variable name has an illegal character i.e.TheWindowsUser which is the value I had assigned to the variable UserName. For a moment I was puzzled how the variable is [...]

## 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-59788da28d573670932109/] List the environments currently created Any of the following commands will give us the list of environments that are already created. [crayon-59788da28d588156735036/] [crayon-59788da28d590697242467/] 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-59788da2962e6469603478/] 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 [...]