Advertisement
Socialking

Untitled

Mar 23rd, 2021
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # Import biblioteki numpy
  2. import numpy
  3.  
  4.  
  5. # Przeliczanie grady na radiany
  6. def grads_to_radians(grads):
  7.     if isinstance(grads, list):
  8.         radians = []
  9.         for grad in grads:
  10.             radians.append((grad * numpy.pi) / 200)
  11.         return radians
  12.     else:
  13.         return (grads * numpy.pi) / 200
  14.  
  15.  
  16. # Przeliczanie radianów na grady
  17. def radians_to_grads(radians):
  18.     if isinstance(radians, list):
  19.         grads = []
  20.         for radian in radians:
  21.             grads.append((radian * 200) / numpy.pi)
  22.         return grads
  23.     else:
  24.         return (radians * 200) / numpy.pi
  25.  
  26.  
  27. # Tablice z wartościami macierzy
  28. # A = [1, 2, 5, 8]
  29. #     [4, -5, 9, 7]
  30. #     [1, 0, 0, 2]
  31. #     [3, 6, 7, 2]
  32. #
  33. # B = [2, 4]
  34. #     [2, 3]
  35. #     [5, 6]
  36. #     [1, 2]
  37.  
  38. A = numpy.array([[1, 2, 5, 8], [4, -5, 9, 7], [1, 0, 0, 2], [3, 6, 7, 2]])
  39. B = numpy.array([[2, 4], [2, 3], [5, 6], [1, 2]])
  40.  
  41. # Zadanie 1
  42. print("## Zadanie nr 1 ##")
  43. print("Grady -> Radiany")
  44. print(grads_to_radians(100))
  45. print(grads_to_radians([100, 50, 20]))
  46. print("#########################\n\n")
  47.  
  48. # Zadanie 2
  49. print("## Zadanie nr 2 ##")
  50. print("Grady -> Radiany")
  51. print(radians_to_grads(100))
  52. print(radians_to_grads([100, 50, 20]))
  53. print("#########################\n\n")
  54.  
  55. # Zadanie 3
  56. print("## Zadanie nr 3 ##")
  57. print("Mnożenie macierzy:")
  58. print(A.dot(B))
  59. print("\n")
  60. print("Macierz transponowana:")
  61. print(A.T)
  62. print("\n")
  63. print("Macierz odwrotna:")
  64. print(numpy.linalg.inv(A))
  65. print("#########################")
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement