Advertisement
Purple666

Untitled

Apr 25th, 2024 (edited)
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. class Employee:
  2.     def __init__(self, name, salary, department, position):
  3.         self.name = name
  4.         self.salary = salary
  5.         self.department = department
  6.         self.position = position
  7.  
  8.     def calculate_emp_salary(self, hours_worked):
  9.         if hours_worked > 50:
  10.             overtime_hours = hours_worked - 50
  11.             overtime_pay = overtime_hours * (self.salary / 50)
  12.             total_salary = self.salary + overtime_pay
  13.         else:
  14.             total_salary = self.salary
  15.         return total_salary
  16.  
  17.     def assign_department(self, new_department):
  18.         self.department = new_department
  19.  
  20.     def print_employee_details(self):
  21.         print("Employee Details:")
  22.         print("Name:", self.name)
  23.         print("Salary:", self.salary)
  24.         print("Department:", self.department)
  25.         print("Position:", self.position)
  26.  
  27.  
  28. # Пример использования класса Employee
  29. employee1 = Employee("John Doe", 50000, "Marketing", "Manager")
  30. employee1.print_employee_details()
  31.  
  32. print("Calculating salary for John Doe...")
  33. total_salary = employee1.calculate_emp_salary(55)
  34. print("Total Salary:", total_salary)
  35.  
  36. print("Assigning new department for John Doe...")
  37. employee1.assign_department("Sales")
  38. employee1.print_employee_details()
  39.  
  40.  
  41. ...
  42.  
  43.  
  44. import numpy as np
  45.  
  46. class ArrayTransformer:
  47.     def __init__(self, p1, p2, p3):
  48.         self.p1 = p1
  49.         self.p2 = p2
  50.         self.p3 = p3
  51.  
  52.     def __call__(self, array):
  53.         if np.random.uniform() < self.p1:
  54.             array = np.flip(array, axis=1)
  55.         elif np.random.uniform() < self.p2:
  56.             array = np.flip(array, axis=0)
  57.        
  58.         if np.random.uniform() < self.p3:
  59.             mean_value = np.mean(array)
  60.             array[array > mean_value] = 1
  61.             array[array <= mean_value] = 0
  62.        
  63.         self.array = array  # сохраняем массив для доступа через __getitem__
  64.         return array
  65.  
  66.     def __getitem__(self, index):
  67.         return self.array[:, :, index]
  68.  
  69. # Пример использования класса ArrayTransformer
  70. p1 = 0.2
  71. p2 = 0.3
  72. p3 = 0.4
  73.  
  74. transformer = ArrayTransformer(p1, p2, p3)
  75. input_array = np.random.rand(20, 20, 10)
  76.  
  77. output_array = transformer(input_array)
  78.  
  79. # Доступ к слоям массива по третьему измерению
  80. index = int(input())
  81. print(transformer[index])
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement