Browse and solve 1,200+ machine learning coding challenges on Deep-ML. Filter by difficulty (beginner, intermediate, advanced) and category (linear algebra, machine learning, deep learning, NLP, computer vision). Write Python solutions in the browser and get instant feedback against test cases.
Write a Python function that calculates the mean of a matrix either by row or by column, based on a given mode. The function should take a matrix (list of lists) and a mode ('row' or 'column') as input and return a list of means according to the specified mode.
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], mode = 'column'
[4.0, 5.0, 6.0]
Calculating the mean of each column results in [(1+4+7)/3, (2+5+8)/3, (3+6+9)/3].