Posts

Showing posts from February, 2016

How to use lists, arrays, Numpy to make life easy with Python?-Part 1

Image
 In my last post ( How to define a function in python? )  we learnt use of the functions in python. All what we learnt is useful for many things but if you are interested to solve mathematical problems using python, you need to know more. The same is true if you have huge databases to analyse. Today we will learn about how do you read and write data using python. This is time to get to know Numpy. I am trying to introduce minimum concepts for the beginners. I will do another blog for advanced python in the future. In the advance part we will see "how Numpy can be used to increase efficiency of python code?".   What is Numpy? I would just like to quote how Numpy is described on their official webpage . NumPy is the fundamental package for scientific computing with Python. It contains among other things: a powerful N-dimensional array object sophisticated (broadcasting) functions tools for integrating C/C++ and Fortran code useful linear algebra, Fourier trans

How to define a function in python?

Image
Use of a function in Python We have learnt few things in our last two posts about python. We started from the  beginning with a python prgoram  and continued with  how to write a for loop in python ?  In this post I will discuss how to write and call a simple function in python. So let us start with simplest function. Start a python notebook as explained in my last posts or if you want to use terminal script then open any text editor and paste the following code. You can also run these codes on my blog at the end of each post. def age (x):       return "Your age is" , x      We defined a very simple function called age(x). This function just prints the value given to it. Let us check how to call it. In [16]: age(20) Out [20]: Your age is 20 We gave input 20 to the function and it printed " Your age is 20 ". Let us now go a level higher and try to write another function. def square (x):    f=x*x      return In [22]: squar