Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.56 KB | None | 0 0
  1. import numpy as np
  2.  
  3. # ======================================================================================================================
  4. # 1 Generator
  5. #
  6. # def my_gen():
  7. #     n = 5
  8. #     yield n
  9. #     n = n * 5
  10. #     yield n
  11. # generator = my_gen()
  12. # a = generator.__next__()
  13. # b = generator.__next__()
  14. # print(str(a) + " " + str(b))
  15.  
  16. # ======================================================================================================================
  17. # 2 Iterator
  18. #
  19. # lista = [1, 2, 3]
  20. # iterator = iter(lista)
  21. # print(next(iterator))
  22. # print(iterator.__next__())
  23. # print(iterator.__next__())
  24.  
  25. # ======================================================================================================================
  26. # 3 Dekorator
  27. #
  28. # def dekorator(funkcja_fun):
  29. #     def inner():
  30. #         print("Wnętrze dekoratora.")
  31. #         return funkcja_fun()
  32. #     return inner
  33. # @dekorator
  34. # def funkcja_udekorowana():
  35. #     print("Coś testowego.")
  36. # def funkcja_bez_dekoratora():
  37. #     print("Coś testowego.")
  38. # funkcja_udekorowana()
  39. # funkcja_bez_dekoratora()
  40.  
  41. # ======================================================================================================================
  42. # 4 Sloty
  43. #
  44. # class KlasaZeSlotami:
  45. #     __slots__ = ['a']
  46. #     def __init__(self, a):
  47. #         self.a = a
  48. # obiekt = KlasaZeSlotami(3)
  49. # obiekt.a = 3
  50. # #obiekt.b = 3 - błąd
  51. # class KlasaBezSlotow:
  52. #     def __init__(self, a):
  53. #         self.a = a
  54. # obiekt = KlasaBezSlotow(3)
  55. # obiekt.a = 3
  56. # obiekt.b = 3
  57.  
  58. # ======================================================================================================================
  59. # Zakres listy
  60. #
  61. # lista = [1, 2, 3, 4, 5, 6, 7, 8]
  62. # print("lista[:]\t\t", lista[:])
  63. # print("lista[-2:]\t\t", lista[-2:])
  64. # print("lista[0:-2]\t\t", lista[:-2])
  65. # print("lista[-2:-2]\t", lista[-2:-2])
  66.  
  67. # # [[9,1][7,3][5,5][3,7][1,9]]
  68. # print(np.concatenate((np.arange(9, 0, -2).reshape(5, 1), np.arange(1, 10, 2).reshape(5, 1)), axis=1))
  69. # # [[3,1],[2,2],[1,3]]
  70. # print(np.concatenate((np.arange(3, 0, -1).reshape(3, 1), np.arange(1, 4, 1).reshape(3, 1)), axis=1))
  71.  
  72. # ======================================================================================================================
  73. # Wytwornik listy
  74. #
  75. # nums = [1, 2, 3, 4, 5]
  76. # new_list1 = [n for n in nums]
  77. # new_list2 = [n * n for n in nums]
  78. # new_list3 = [n for n in nums if n % 2 == 0]
  79. # new_list4 = [(letter, number) for letter in "abcd" for number in range(4)]
  80. # print(new_list1)
  81. # print(new_list2)
  82. # print(new_list3)
  83. # print(new_list4)
  84.  
  85. # ======================================================================================================================
  86. # np.linspace(początek, koniec, ile_wartości_z_zakresu)
  87. #
  88. # lista = np.linspace(1, 3, 5)
  89. # print(lista)
  90.  
  91. # ======================================================================================================================
  92. # PYQT
  93. #
  94. # from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QHBoxLayout
  95. # app = QApplication([])
  96. # window = QWidget()
  97. # layout = QHBoxLayout()
  98. # layout.addWidget(QPushButton('Top'))
  99. # layout.addWidget(QPushButton('Bottom'))
  100. # window.setLayout(layout)
  101. # window.show()
  102. # app.exec_()
  103.  
  104. # ======================================================================================================================
  105. # Numpy 3x3 tablica, liczby od 0 do 8
  106. #
  107. # lista = np.arange(0, 9, 1).reshape(3, 3)
  108. # print(lista)
  109.  
  110.  
  111. # ======================================================================================================================
  112. # Zbiory
  113. #
  114. # A = {1, 2, 3, 4, 5}
  115. # B = {4, 5, 6, 7, 8}
  116. # print(A.union(B))  # scalenie zbiorów i usunięcie powtórzeń
  117. # print(A.intersection(B))  # te elementy co ma zbiór A i B
  118. # print(A.difference(B))  # co ma A czego nie ma B
  119. # print(B.difference(A))  # co ma B czego nie ma A
  120. # print(A.symmetric_difference(B))  # suma A.difference(B) i B.difference(A), albo inaczej wszystko bez części wspólnej
  121.  
  122. # ======================================================================================================================
  123. # Przeciążenie operatorów (zamiana dodawania z odejmowaniem)
  124. #
  125. # class Odwrotek:
  126. #     def __init__(self, a):
  127. #         self.a = a
  128. #
  129. #     def __add__(self, other):
  130. #         return self.a - other.a
  131. #
  132. #     def __sub__(self, other):
  133. #         return self.a + other.a
  134. #
  135. #
  136. # A = Odwrotek(5)
  137. # B = Odwrotek(5)
  138. # print(A + B)
  139. # print(A - B)
  140.  
  141. # ======================================================================================================================
  142. # Jednolinijkowiec generujący tablice [[6,3][5,2][4,1]] biblioteka numpy zaimportowana jako np:
  143. #
  144. # print(np.concatenate((np.arange(6, 3, -1).reshape(3, 1), np.arange(3, 0, -1).reshape(3, 1)), axis=1))
  145.  
  146. # ======================================================================================================================
  147. # Jednolinijkowiec policzyć średnia dla wierszy i kolumn macierzy
  148. #
  149.  
  150. # ======================================================================================================================
  151. # Typy liczbowe w Python: int(), float() oraz complex()
  152. #
  153. # integeros = int(3)
  154. # print(integeros)
  155. # floateros = float(3.0)
  156. # print(floateros)
  157. # complexeros = complex(3.0)
  158. # print(complexeros)
  159.  
  160. # ======================================================================================================================
  161. # Co wyświetli kod?
  162. #
  163. # regularList = [1, 2, 3]
  164. # print("regularList\t" + str(type(regularList)))
  165. # numpyList = np.arange(0, 2, 4)
  166. # print("numpyList\t" + str(type(numpyList)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement