Creating input (x) and target (y) for RNNs

When creating training data for RNN, the target label for a given input label is the input label itself but shifted by one position. Please refer to the diagram below.

charRNN@0.5x
Continue reading “Creating input (x) and target (y) for RNNs”

Usage of enumerate() with python list

enumerate() is a useful function to make an iterator when used with a for loop. Here we explain different ways of using
enumerate() using a python list. enumerate() acts as an iterator yielding a tuple (index,element)when applied on a list.

Continue reading “Usage of enumerate() with python list”

View python source code inside packages

matrix_code

Often we want to know how a function is written in an imported package. This post explains how to examine the source code of a function/class.

To know where the package is installed:

[package_name].__file__

For the package pandas:

import pandas
pandas.__file__

To examine the source code of a given function or class, import the package inspect.

import inspect as insp
print insp.getsourcefile(pandas.DataFrame) # prints the path to source file

print insp.getsourcelines(pandas.DataFrame) # prints the source code

Documentation of inspect package can be found here.

Viewing the source code from IPython Notebook

Append ? to the function name inside the ipython-notebook cell to view code description and ?? for the entire source code.


import pandas

pandas.DataFrame? # shows the docstring

pandas.DataFrame?? # shows the source code and docstring