Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Employee:
- def __init__(self, name, salary, department, position):
- self.name = name
- self.salary = salary
- self.department = department
- self.position = position
- def calculate_emp_salary(self, hours_worked):
- if hours_worked > 50:
- overtime_hours = hours_worked - 50
- overtime_pay = overtime_hours * (self.salary / 50)
- total_salary = self.salary + overtime_pay
- else:
- total_salary = self.salary
- return total_salary
- def assign_department(self, new_department):
- self.department = new_department
- def print_employee_details(self):
- print("Employee Details:")
- print("Name:", self.name)
- print("Salary:", self.salary)
- print("Department:", self.department)
- print("Position:", self.position)
- # Пример использования класса Employee
- employee1 = Employee("John Doe", 50000, "Marketing", "Manager")
- employee1.print_employee_details()
- print("Calculating salary for John Doe...")
- total_salary = employee1.calculate_emp_salary(55)
- print("Total Salary:", total_salary)
- print("Assigning new department for John Doe...")
- employee1.assign_department("Sales")
- employee1.print_employee_details()
- ...
- import numpy as np
- class ArrayTransformer:
- def __init__(self, p1, p2, p3):
- self.p1 = p1
- self.p2 = p2
- self.p3 = p3
- def __call__(self, array):
- if np.random.uniform() < self.p1:
- array = np.flip(array, axis=1)
- elif np.random.uniform() < self.p2:
- array = np.flip(array, axis=0)
- if np.random.uniform() < self.p3:
- mean_value = np.mean(array)
- array[array > mean_value] = 1
- array[array <= mean_value] = 0
- self.array = array # сохраняем массив для доступа через __getitem__
- return array
- def __getitem__(self, index):
- return self.array[:, :, index]
- # Пример использования класса ArrayTransformer
- p1 = 0.2
- p2 = 0.3
- p3 = 0.4
- transformer = ArrayTransformer(p1, p2, p3)
- input_array = np.random.rand(20, 20, 10)
- output_array = transformer(input_array)
- # Доступ к слоям массива по третьему измерению
- index = int(input())
- print(transformer[index])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement