Skip to content

Instantly share code, notes, and snippets.

@ramesaliyev
Created September 3, 2024 05:03
Show Gist options
  • Save ramesaliyev/b56bfbb7b9987303c85e8d041e7b632b to your computer and use it in GitHub Desktop.
Save ramesaliyev/b56bfbb7b9987303c85e8d041e7b632b to your computer and use it in GitHub Desktop.
def min_max(data):
min_approx = np.zeros(data.shape)
max_approx = np.zeros(data.shape)
for i, row in enumerate(data):
for j, _ in enumerate(row):
col = data[:, j]
vec = np.concatenate([row, col])
q1 = np.percentile(vec, 25, axis=0, keepdims=False)
q3 = np.percentile(vec, 75, axis=0, keepdims=False)
iqr = q3 - q1
lower_whisker = q1 - 1.5 * iqr
upper_whisker = q3 + 1.5 * iqr
min_approx[i, j] = np.maximum(lower_whisker, np.min(row))
max_approx[i, j] = np.minimum(upper_whisker, np.max(row))
return min_approx, max_approx
# np.random.seed(0) # for reproducibility
employees = 5
days = 7
mins = [
[2, 8, 2, 2, 2, 2, 2],
[2, 2, 2, 2, 2, 2, 2],
[2, 2, 2, 2, 2, 2, 2],
[2, 2, 2, 2, 2, 2, 2],
[2, 2, 2, 2, 2, 2, 2],
]
maxs = [
[8, 16, 8, 8, 8, 8, 8],
[8, 8, 8, 8, 8, 8, 8],
[8, 8, 8, 8, 8, 8, 8],
[8, 8, 8, 8, 8, 8, 8],
[8, 8, 8, 8, 8, 8, 8],
]
working_hours = np.random.uniform(mins, maxs, size=(employees, days)).astype(int)
min_approx, max_approx = min_max(working_hours)
print("Original working hours matrix:")
print(working_hours)
print("\nApproximated minimum working hours:")
print(min_approx)
print("\nApproximated maximum working hours:")
print(max_approx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment