You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 KiB

None <html> <head> </head>

How Jupyter works

In [1]:
print(x)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In [1], line 1
----> 1 print(x)

NameError: name 'x' is not defined
In [2]:
x=3

Basic commands

Jupyter Notebook is widely used for data analysis. The notebooks documents are documents produced by the Jupyter Notebook App, which can contain both code (e.g. Python) and rich text elements (paragraphs, equations, links, etc.).

The Jupyter Notebook App is a client-server application that allows editing and running notebook documents by a browser.

Shortcuts in both modes:

  • Shift + Enter run the current cell, select below
  • Ctrl + Enter run selected cells
  • Alt + Enter run the current cell, insert below
  • Ctrl + S save and checkpoint

While in command mode (press Esc to activate):

Enter take you into edit mode

  • H show all shortcuts
  • Up select cell above
  • Down select cell below
  • Shift + Up extend selected cells above
  • Shift + Down extend selected cells below
  • A insert cell above
  • B insert cell below
  • X cut selected cells
  • C copy selected cells
  • V paste cells below
  • Shift + V paste cells above
  • D, D (press the key twice) delete selected cells
  • Z undo cell deletion
  • S Save and Checkpoint
  • Y change the cell type to Code
  • M change the cell type to Markdown
  • P open the command palette

This dialog helps you run any command by name. Its really useful if you dont know some shortcut or when you dont have a shortcut for the wanted command.

  • Shift + Space scroll notebook up
  • Space scroll notebook down

While in edit mode (press Enter to activate)

  • Esc take you into command mode
  • Tab code completion or indent
  • Shift + Tab tooltip
  • Ctrl + ] indent
  • Ctrl + [ dedent
  • Ctrl + A select all
  • Ctrl + Z undo
  • Ctrl + Shift + Z or Ctrl + Y redo
  • Ctrl + Home go to cell start
  • Ctrl + End go to cell end
  • Ctrl + Left go one word left
  • Ctrl + Right go one word right
  • Ctrl + Shift + P open the command palette
  • Down move cursor down
  • Up move cursor up

Basics of Python and Programming

Using conditionals

In [3]:
x = 1 #int(input('Introduce un numero: '))
if x<0:
    print('El valor es negativo')
else:
    print("El valor es positivo")
El valor es positivo
In [5]:
x = int(input('Introduce un numero: '))
if x<0:
    print('El valor es negativo')
else:
    print("El valor es positivo")
Introduce un numero: -5
El valor es negativo

Using for loops

In [6]:
nombres = ['juan', 'israel', 'jonathan', 'homero']
for n in nombres:
    print(n)
juan
israel
jonathan
homero
In [7]:
for n in range(1,11):
    print(n)
1
2
3
4
5
6
7
8
9
10

Arrays and indexing

In [4]:
import numpy as np
a = np.array([[1,2],[3,4],[5,6]])

Functions

In [7]:
# how to crate functions
def myFuncion(x):
    y = np.sin(x)/np.cos(x)
    return y

Making basic plots

In [10]:
import matplotlib.pyplot as plt
time = np.linspace(0,10)
y = myFuncion(time)
y2 = np.tan(time)
plt.plot(time, y/2,'-g*')
plt.plot(time, y2, ':m+')
plt.show()

Subplot

In [11]:
plt.subplot(3,1,1)
plt.plot(time, np.sin(time),'r', label='$y_1$')
plt.legend()
plt.subplot(3,1,2)
plt.plot(time, np.cos(time),'g',label='y2')
plt.legend()
plt.subplot(3,1,3)
plt.plot(time, np.tan(time),'k', label='y3')
plt.legend()
plt.show()

Some additions task and work

  • Make function that computes the factorial of a given numer using for loops
  • Make a function that computes 4 functions (sin, cos, tan, logistic) and plots
  • Make a function that recive your age and classifies you as baby, teenager, ....
In [ ]:

</html>