In [1]:
#import libraries:
import numpy as np
In [2]:
print("This is a cell")
print("Press Strg + ENTER to execute the current cell!")
print("Press Shift + ENTER to execute the current cell and jump to the next cell!")
In [3]:
print("An average example in python")
var = 5 # variable
list_of_numbers = [1, 2, 3, 4, var] # a list of numbers
mean = np.mean(list_of_numbers) # calculating the average
print("M=", mean) # printing the result
print("num at 2:", list_of_numbers[2]) # indexing
print() # just a new line
print("Dictionaries are useful!")
d = dict()
d["key"] = "value" # storing something in the dict with key
print("Whole dict:", d)
print("dict with key:", d["key"])
In [4]:
# Define a function like this
def func(param1, param2, and_so_on):
print(param1, param2, and_so_on)
# Then call it
func("p1", [1, 2, 3], {"this", "is", "a", "a", "a", "set"})
In [5]:
# Define classes like this
class AI:
# init function for declaring all the variables of the class
def __init__(self):
self.iq = 9001
# a function of the class
def solve_problem(self, p):
print("solving", p)
self.process_something(10)
return "¯\_(ツ)_/¯ but my IQ is " + str(self.iq)
def process_something(self, n):
for i in range(n): # for - loop
print("working...")
if i == 9 and i is 9: # if - statement
print("Done!")
ai = AI()
print(ai.solve_problem("P vs NP"))
In [6]:
print("Basic Maths with numpy")
a = 4
print("a =", a)
result = np.power(a, 2) # b to the power of 2
print(result)
result += 1 # increment
print(result)
result -= 1 #decrement
print(result)
result = np.log2(result) # logarithmus dualis
print(result)
result = np.sqrt(result) # square root
print(result)
while True: # while true loop
print("And so on and so on...")
break # break the loop