Interview Query

Matrix Analysis

Upvote
4
Downvote
Save
Mark Completed
Have you seen this question before?

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]]
Next question: Advertisement Matching
.....
Loading editor
Use Shift + Enter to run

Comments

Loading comments