"Remove Element with index n from list (indexing also negative possible)"
"a_list.pop(n)"
"Method"
"Specific function for a class of objects "
"Insert an element at and index to a list"
"a_list.insert(2, ""Hello"") "
"Insert an element directly at the end of a list"
"a_list.append(""Element"")"
"Merging two lists together (sie werden direkt hintereinander gehängt, erst list1 dann list2"
"list_1.extend(list_2) geht auch mit plus list_1 = list_1 + list_2"
"Difference List and Tuple"
"Tuple with or without paranthesis (brauchen keine klammern), tuples are immutable "
"Tuple assignment"
"Assignment of values to serveral variables simultaneously // x, y, z = a_tuple // a, b = b, a"
"Dictionary form / define a dict"
"a_dict = {key1 : value1, key2 : value2, ...} "
"Calling from a dict "
"a_dict[""key1""] = value1"
"Adding a new key to the dictionary"
"a_dict[""new key""] = a_value"
"Deletion of the key ""a key"""
"a_dict.pop(""a key"")"
"Method pop"
"Argument: index, decription: removes element from the list located at the specified index "
"Method insert"
"Argument, index, value Description Adds a new element tot he list at the secified index "
"Method append"
"Argument value
"extend"
"Argument list: merges the list caling the method with the list in argument "
"Operator: Floor division"
"// reflects how many time the numer on the right can fully divide the number on the left (6 // 4 retunrs 1) "
"Operator: Modulus %"
"Gives the remainder of the floor division 6 % Modulus 4 gives 2 "
"Assignment Operators +="
"x += 3 -> steht für x = x + 3 gleiches gilt für total += number /// oder modulus %="
"Boolean value "
"True or False "
"Is x less than y? "
"x < y"
"Is x lesser or equal to y?"
"x <= y "
"Is x different from y?"
"x != y"
"Is x equal to y? "
"x == y "
"Membership operators: test wheather a value is absent or present in a sequence, list or tuple "
"x in a_list /oder/ x not in a_list"
"Is 5 divisible by 3?"
"5 % 3 ==0 "
"Boolean arithmetics: both expresions true?"
"print(expression 1 and expression2)"
"Boolean arithmetics: at least one expresion of P and Q true"
"print(P or Q) "
"Boolean arithmetics: the negation of the expresion P"
"print(not P)"
"intented"
"shifted by one tabulation or 4 spaces"
"Contraction of else and if"
"elif (wie eine unterteilung zwischen if und else: elif grade <15: oder elif grade < 10: "
"Conditional assignment"
"redouble = True if average < 10 else False"
"Unterbrechungen von while loops "
"if i==1: break"
"range function"
"range(start,stop,increment). by default it is start 0 and step 1/ das ist super für for loop functions "
"slicing and reversing the order of a word "
"word[::-1] (from the beginning to the end with two : and-1 indicates the step direction"
"Nested loops: "
"When you have a list of lists, it is possible to browse all its elements with two nesdet loops."
"Palindrom testing with list comprehension and slicing technique "
"palindromes = [word for word in l if word==word[::-1]]"
"Enumerate function"
"for index, element in enumerate(sequence): (einfach variablen in index und element eintragen, und sequence ist die liste"
"maximum of a list / minimum"
"max(l) / min(l)"
"sum of a list "
"sum(list) = gibt mir schon die summe zurück"
"zip function"
"for element1, element2 in zip(sequence1, sequence2) #at each iteration we take an element from each sequence "
"Benefit of a function"
"Able to store the result as a variable and use it globaly later "
"Checking if element is in List "
"if element in List: >>> gives back bolean // or if element not in List:>>> bolean "
"Großes Kommentar ZeilenBlock"
""""""" define the start and end of the definition in a function "
"Informationen einer Function (standard bib bei python) einsehen"
"help(function) bsp.: help(len) --- no print is needed "
"Container"
" A ""container"" is any object that can be iterated over such as a list, a tuple, a string, etc."
"Recursive function"
"Simplify a problem until it is trivial, heist die funktion ruft sich so lange selbst wieder auf bis sie bei bswp 2 Personen angekommen ist. Macht bei fakultät berechnungen sinn N! (immer schauen das am ende soetwas steht wie return function(N-1) damit nicht ewiglich selbst aufrufend "
"3 fundamental elements in an object class"
"A constructor (function that initializes an object of the class), attributes (variables, specific to the created object used to define its properties and store information, Methos (class-specific functions that allow you to interact with an object) "
"Keyword: class"
"This allows us to start a block of code where we can define the constructor of the class and its methods. "
"__init__"
"Definition of the constructor, allows to initialize the attributes of the object."
"Self argument in an attribute"
"The self argument corresponds to the object calling the method. This argument allows us to access the attributes of the object within the method. All the moethods of a class must have self as first argument. "
"Instantiation"
"Process of building an object and assigning it to a variable. (C1 = Complex(3,2)"
"help(class)"
"will print out all the comments and also divides into the methods (subfunctions) within the object class "
"Module"
"Also known as package or library / python file containing definitions of classes and functions. "
"Keys in dictionaries"
"Remember that a dictionary is a data structure where the data is indexed by keys. To access a key from a dictionary, all you have to do is enter the key in square brackets"
"numpy array"
"N-dimensional matrices, can contain diverse data, such as table, data, time series or images"
"Creating a 3D tuple with 1s in shape 5,10,10"
"X = np.ones(shape = (5,10,10))"
"Displaying element at index (4, 3) in array X"
"print(X[4,3])"
"Array positions nomenklatur in numpy"
"LinkeHandRegel // X[linie from top down, spalte from left to right, Z-direciton from fron to back]"
"Slicing of arrays, cut out line 2 (actually line 3)"
"X[2,:] oder anderes beispiel X[1:4, 2:5]"
"Rounding in numpy"
"np.round(x, decimals = n)"
"Anzahl elemente in liste, bzw größe von Array"
"array.shape"
"Conditioning of arrays "
"X[X < 0] = 0 (to all neg elements we assign value 0) // X[y == 1] = -1 value -1 for all elements which are same in X and y arrays"
"Displaying the elements of X for which the value of y at the corresponding index is 0"
"print(X[y == 0])"
"Create an np array from 1 to 10"
"X = np.array([i for i in range(1, 11)]) # 1, 2, ..., 10"
"Reshaping the array (of 10) into a matrix with 2 rows and 5 columns "
"X_reshaped = X.reshape((2, 5))"
"Rules for numpy array.reshape((sixe_y, size_x))"
" both shapes contain the same number of elements"
"Array compatibility with scikit-learn algorithms"
"incapable of processing matrix data, the original 1797 images of 8x8 dimensions were flattened into vectors of size 8x8 = 64."
"Merge several arrays to build dataset in np"
"np.concatenate([X_1, X_2], axis = 0) // The arrays to concatenate must be passed as a list or a tuple. //The axis argument determines the dimension on which the arrays should be concatenated. The arrays must have the same length on this dimension. //In the case of a 2-dimensional array, an operation along axis 0 corresponds to an operation along the row-axis (the first dimension), while an operation along axis 1 pertains to the column-axis (the second dimension)."
"Shape of numpy arrays "
"M = np.array([a,b],[c,d]) -> erste reihe is a und b, zweite reihe in der Matrix is c, d"
"Matrix product in numpy (kreuzprodukt von M und N)"
"Kreuzprodukt = M.dot(N)"
"Numpy broadcasting // broadcasting: adding constant to matrix "
"performing operation between elements of different dimension // Constant C + each element on matrix (like a c filled ones matrix)"
"Constraints of broadcasting a vector into a matrix"
"The dimensions are equal, one of the dimension is equal to 1. If for each dimension one of these conditions are verified it is compatible. (but dimension 1 with dimension 1 and dimension 2 with 2 and so on) "
"Numpy min max methodik für normalisierung von arrays"
"normalized_data = (data - data.min()) / (data.max() - data.min()) "
"Transposition of an Array with Numpy"
"Array transposition X_T = X.T"
"Minimum, Maximum, Mean in einem Numpy array"
"X.min() und X.max() und X.mean() // X.mean(axis = 0) berechnet von jeder spalte column den mean bei axis = 1, mean von jeder Zeile"
"Other np.functions that require axis argument"
"sum / std: standard deviation / min, max, argmin (find minimum and gives back indized), argmax (same) "
Last changed4 days ago