Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- # ======================================================================================================================
- # 1 Generator
- #
- # def my_gen():
- # n = 5
- # yield n
- # n = n * 5
- # yield n
- # generator = my_gen()
- # a = generator.__next__()
- # b = generator.__next__()
- # print(str(a) + " " + str(b))
- # ======================================================================================================================
- # 2 Iterator
- #
- # lista = [1, 2, 3]
- # iterator = iter(lista)
- # print(next(iterator))
- # print(iterator.__next__())
- # print(iterator.__next__())
- # ======================================================================================================================
- # 3 Dekorator
- #
- # def dekorator(funkcja_fun):
- # def inner():
- # print("Wnętrze dekoratora.")
- # return funkcja_fun()
- # return inner
- # @dekorator
- # def funkcja_udekorowana():
- # print("Coś testowego.")
- # def funkcja_bez_dekoratora():
- # print("Coś testowego.")
- # funkcja_udekorowana()
- # funkcja_bez_dekoratora()
- # ======================================================================================================================
- # 4 Sloty
- #
- # class KlasaZeSlotami:
- # __slots__ = ['a']
- # def __init__(self, a):
- # self.a = a
- # obiekt = KlasaZeSlotami(3)
- # obiekt.a = 3
- # #obiekt.b = 3 - błąd
- # class KlasaBezSlotow:
- # def __init__(self, a):
- # self.a = a
- # obiekt = KlasaBezSlotow(3)
- # obiekt.a = 3
- # obiekt.b = 3
- # ======================================================================================================================
- # Zakres listy
- #
- # lista = [1, 2, 3, 4, 5, 6, 7, 8]
- # print("lista[:]\t\t", lista[:])
- # print("lista[-2:]\t\t", lista[-2:])
- # print("lista[0:-2]\t\t", lista[:-2])
- # print("lista[-2:-2]\t", lista[-2:-2])
- # # [[9,1][7,3][5,5][3,7][1,9]]
- # print(np.concatenate((np.arange(9, 0, -2).reshape(5, 1), np.arange(1, 10, 2).reshape(5, 1)), axis=1))
- # # [[3,1],[2,2],[1,3]]
- # print(np.concatenate((np.arange(3, 0, -1).reshape(3, 1), np.arange(1, 4, 1).reshape(3, 1)), axis=1))
- # ======================================================================================================================
- # Wytwornik listy
- #
- # nums = [1, 2, 3, 4, 5]
- # new_list1 = [n for n in nums]
- # new_list2 = [n * n for n in nums]
- # new_list3 = [n for n in nums if n % 2 == 0]
- # new_list4 = [(letter, number) for letter in "abcd" for number in range(4)]
- # print(new_list1)
- # print(new_list2)
- # print(new_list3)
- # print(new_list4)
- # ======================================================================================================================
- # np.linspace(początek, koniec, ile_wartości_z_zakresu)
- #
- # lista = np.linspace(1, 3, 5)
- # print(lista)
- # ======================================================================================================================
- # PYQT
- #
- # from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QHBoxLayout
- # app = QApplication([])
- # window = QWidget()
- # layout = QHBoxLayout()
- # layout.addWidget(QPushButton('Top'))
- # layout.addWidget(QPushButton('Bottom'))
- # window.setLayout(layout)
- # window.show()
- # app.exec_()
- # ======================================================================================================================
- # Numpy 3x3 tablica, liczby od 0 do 8
- #
- # lista = np.arange(0, 9, 1).reshape(3, 3)
- # print(lista)
- # ======================================================================================================================
- # Zbiory
- #
- # A = {1, 2, 3, 4, 5}
- # B = {4, 5, 6, 7, 8}
- # print(A.union(B)) # scalenie zbiorów i usunięcie powtórzeń
- # print(A.intersection(B)) # te elementy co ma zbiór A i B
- # print(A.difference(B)) # co ma A czego nie ma B
- # print(B.difference(A)) # co ma B czego nie ma A
- # print(A.symmetric_difference(B)) # suma A.difference(B) i B.difference(A), albo inaczej wszystko bez części wspólnej
- # ======================================================================================================================
- # Przeciążenie operatorów (zamiana dodawania z odejmowaniem)
- #
- # class Odwrotek:
- # def __init__(self, a):
- # self.a = a
- #
- # def __add__(self, other):
- # return self.a - other.a
- #
- # def __sub__(self, other):
- # return self.a + other.a
- #
- #
- # A = Odwrotek(5)
- # B = Odwrotek(5)
- # print(A + B)
- # print(A - B)
- # ======================================================================================================================
- # Jednolinijkowiec generujący tablice [[6,3][5,2][4,1]] biblioteka numpy zaimportowana jako np:
- #
- # print(np.concatenate((np.arange(6, 3, -1).reshape(3, 1), np.arange(3, 0, -1).reshape(3, 1)), axis=1))
- # ======================================================================================================================
- # Jednolinijkowiec policzyć średnia dla wierszy i kolumn macierzy
- #
- # ======================================================================================================================
- # Typy liczbowe w Python: int(), float() oraz complex()
- #
- # integeros = int(3)
- # print(integeros)
- # floateros = float(3.0)
- # print(floateros)
- # complexeros = complex(3.0)
- # print(complexeros)
- # ======================================================================================================================
- # Co wyświetli kod?
- #
- # regularList = [1, 2, 3]
- # print("regularList\t" + str(type(regularList)))
- # numpyList = np.arange(0, 2, 4)
- # print("numpyList\t" + str(type(numpyList)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement