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.
157 KiB
157 KiB
None
<html>
<head>
</head>
</html>
How Jupyter works¶
In [1]:
print(x)
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 and also considers that some commands en Google collab have been modified and require first the Ctr+M
command and then the command that you need like change the cell type to Markdown:
- H show all shortcuts
Ctr+M
- 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
Ctr+M
- Z undo cell deletion
- S Save and Checkpoint
Ctr+M
- Y change the cell type to Code
Ctr+M
- M change the cell type to Markdown
Ctr+M
- P open the command palette
Ctr+M
This dialog helps you run any command by name. It’s really useful if you don’t know some shortcut or when you don’t 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
In [3]:
x = 1 #int(input('Introduce un numero: '))
if x<0:
print('El valor es negativo')
else:
print("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")
Using for loops¶
In [6]:
nombres = ['juan', 'israel', 'jonathan', 'homero']
for n in nombres:
print(n)
In [7]:
for n in range(1,11):
print(n)
Arrays and indexing¶
In [3]:
import numpy as np
a = np.array([[1,2],[3,4],[5,6]])
Functions¶
In [5]:
# how to crate functions
def myFuncion(x):
y = np.sin(x)/np.cos(x)
return y
Making basic plots¶
In [6]:
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 [7]:
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()
In [8]:
plt.subplot(6,3,1)
plt.plot(time, np.sin(time),'r', label='y_1')
plt.subplot(6,3,2)
plt.plot(time, np.cos(time),'g',label='y2')
plt.subplot(6,3,3)
plt.plot(time, np.tan(time),'k', label='y3')
plt.subplot(6,3,4)
plt.plot(time, np.sin(time),'r', label='$y_1$')
plt.subplot(6,3,5)
plt.plot(time, np.cos(time),'g',label='y2')
plt.subplot(6,3,6)
plt.plot(time, np.tan(time),'k', label='$y_1$')
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, ....
factorial¶
In [9]:
def factorial(argument):
mul=1
for n in range(1,argument):
prod = mul*(n+1)
mul = prod
print(prod)
pass
In [11]:
factorial(7)
making plots¶
In [19]:
def myPlots(x):
y1 = np.sin(x)
y2 = np.cos(x)
y3 = np.tan(x)
y4 = 1/(1+np.exp(-x))
#plots
plt.figure(figsize=(10,10))
plt.subplot(4,4,1)
plt.plot(x, y1)
plt.subplot(4,4,2)
plt.plot(x, y2)
plt.subplot(4,4,3)
plt.plot(x, y3)
plt.subplot(4,4,4)
plt.plot(x, y4)
pass
In [21]:
x = np.linspace(-10,10)
myPlots(x)
Age classificator¶
In [44]:
def AgeClassificator(age):
if age<=2:
print('You are a baby')
else:
if age <=12:
print('you are a children')
else:
if age<=18:
print('you are a teenager')
else:
if age <=40:
print('you are young')
else:
print('You are old-younger')
pass
In [45]:
AgeClassificator(41)