Interview Query

Matrix Analysis

Start Timer

0:00:00

Upvote
6
Downvote
Save question
Mark as completed
View comments (21)
Next question

Let’s say we have a five-by-five matrix num_employees where each row is a company and each column represents a department. Each cell of the matrix displays the number of employees working in that particular department at each company.

Write a function find_percentages to return a five by five matrix that contains the portion of employees employed in each department compared to the total number of employees at each company.

Example:

Input:

import numpy as np
#Input:
num_employees = np.array( [[10, 20, 30, 30, 10], [15, 15, 5, 10, 5], [150, 50, 100, 150, 50], [300, 200, 300, 100, 100], [1, 5, 1, 1, 2]] )

Output:

def find_percentages(num_employees) ->
#Output:
percentage_by_department = [[0.1, 0.2, 0.3, 0.3, 0.1], [0.3, 0.3, 0.1, 0.2, 0.1], [0.3, 0.1, 0.2, 0.3, 0.1], [0.3, 0.2, 0.3, 0.1, 0.1], [0.1, 0.5, 0.1, 0.1, 0.2]]
.
.
.
.
.


Comments

Loading comments.