MR_Lab_1_IntroductionToNotebook

ipynb7 kBPython · 10 cellsIn Lab 1: Introduction to notebooks

Introduction to Artificial Intelligence

-- At the end of this session, you will be able to :

  • Create and manage the Jupyter Notebooks environment to run code, insert text and math equations.
  • Perform basic matrix manipulations using Numpy.

Intro to Jupyter Notebook

-- Here, we will only cover the basics.

Jupyter Notebook is based on the .ipynb format (iPython Notebook), and is essentially a way to do rapid prototyping / demonstrations of scientific python. The basic idea is to define cells. Cells can be of several types, including python code, or rich text (using markdown formatting).

When a code cell is evaluated (i.e. the python code will be executed), the output of this evaluation will show up right below the cell.

When a text cell is evaluated, the text will be formatted.

You can now do the "User Interface Tour" from the Help menu.

When working with Jupyter Notebook, you will essentially switch between two modes :

  • The Edit mode in which you edit the content of the cells
  • The Command mode, that enables you to change the cell types.

When in Command mode, you can select cells. If you select a single cell, you can edit it by simply pressing enter, or double clicking on it.

For example, try editing THIS CELL and change its content.

Now, edit the cell below, change the code, and when you're done, press Shift+Enter to evalute the code.

In [1]
### CELL TO BE EDITED

a=32
b= 2*a
print("%d + %d"%(a,b))

### CELL TO BE COMPLETED 
32 + 64

Note that using Jupyter Notebook, if you evaluate a cell with a function followed by a ? sign, the help of the function will pop up.

Example :

In [2]
import os

os.listdir?
Signature: os.listdir(path=None)
Docstring:
Return a list containing the names of the files in the directory.

path can be specified as either str, bytes, or a path-like object.  If path is bytes,
  the filenames returned will also be bytes; in all other circumstances
  the filenames returned will be str.
If path is None, uses the path='.'.
On some platforms, path may also be specified as an open file descriptor;\
  the file descriptor must refer to a directory.
  If this functionality is unavailable, using it raises NotImplementedError.

The list is in arbitrary order.  It does not include the special
entries '.' and '..' even if they are present in the directory.
Type:      builtin_function_or_method

You can also display the code of a function using the syntax "??"

In [3]
B = 2.5
B?
Type:        float
String form: 2.5
Docstring:   Convert a string or number to a floating-point number, if possible.
In [4]
### CELL TO BE COMPLETED