02-01 Lists

Data Structures¶In the previous modules, we learnt about python’s built-in ‘simple’ types. In this module, we will learn about the different ways in which the data of those types can be organized, so that it can be used (algorithmically) efficiently. we have already covered str, int, float, and complex. Here, we will also introduce the remaining two – bool and None python’s built-in types Python’s most basic data structure is the sequence.

02-02 Tuples

01 - 06 Tuples¶Python tuple is much like a list except that it is immutable or unchangeable once created. Tuples use parentheses and creating them is as easy as putting different items separated by a comma between parentheses. In [1]: my_tup = ('Python', 'Julia', 1, 3.1415) type(my_tup) Out[1]: tuple Pretty easy.. so the next question is why do we need a new datatype?

02-03 Dictionaries

01 - 07 Dictionaries¶Python dictionary is an interesting and useful data structure in python. It is a container of key-value pairs. Just like lists, python dictionaries are mutable and can contain mixed types, however the key must be immutable (i.e the object being used as a key must be hashable) – e.g. like strings or numbers or even Tuples and must be unique within a dictionary. Python dictionaries are also known as hash tables in other programming languages.

02-04 Functions

02 - 04 Functions¶Imagine that you have to open a file, read the contents of the file and close it. Pretty trivial, right? Now imagine that you have to read ten files, print their output or perform some computation on the contents and then close it. Now you don’t want to sit there and type file i/o operations for every file. What if there are over 500 files? This is where the functions come in.

02-05 Exception Handling

02 - 05 Exception Handling¶An exception is a python object that represents an error. It is an event, which occurs during the execution of a program that disrupts the normal flow of the program’s instructions. When such a situation occurs and if python is not able to cope with it, it raises and exception. We have been seeing errors like TypeError and NameError or IndentationError throughout our tutorial which caused our application or that code to stop the execution.

02-06 File IO

02 - 06 File I/O¶Before we jump in to file I/O functions, lets first look at some basic I/O functions that are available to use in Python. In Python, there are three basic I/O connections, Standard Input, Standard Output and Standard Error. As the name suggests, Standard Input is the data that goes to the program through the keyboard. keyboard being the standard input. Standard output is the terminal console, unless redirected.

03-00 Introduction to Numpy

03 - 00 Introduction to Numpy¶Numpy (Numerical Python) is an opensource library for performing scientific computation in python. Numpy let’s you work with arrays and matrices in a natural way unlike lists where you have to loop through individual elements to perform any numerical operation. This would probably be a good time to refresh your memory on what are arrays and matrices.. here is something that you need to know to get started

03-01 Numpy Array Basics

03 - 01 Numpy Array Basics¶Numpy’s main object is the homogeneous multidimensional array. Numpy’s array class is called ndarray. It is a table of numbers, indexed by a tuple of positive integers. In numpy dimensions are called as axes. The number of axes is known as rank. Numpy arrays are similar to Python lists with few differences such as: All the elements in a numpy array must be of same datatype.

03-02 Ufuncs

03 - 02 Ufuncs¶Python’s default implementation does some operations slowly. This is in part due to the dynamic and interpreted nature of the language. It is this feature that allows types to be flexible but since the type has to be checked at every operation, the sequences of operations cannot be compiled down to efficient machine code as in languages like C. Lets take a look at python native implementation of this:

03-03 Broadcasting and computation

03 - 03 Broadcasting and more Computation¶03 - 03.01 Broadcasting¶Broadcasting is a set of rules for applying ufuncs (e.g., addition, subtraction, multiplication, etc.) on arrays of different sizes. It is an important functionality to leverage the power of Numpy. If you remember from previous module, ufunc operations are performed element-by-element wise. Lets take a look at adding a scalar (we did this in Arithmetic subsection of previous module) In [1]: from future import print_function import numpy as np arr1 = np.