Mean by Row or Column

Matrix Algebra DS practice problem on Onlearn.

Difficulty: easy.

Topics: Understanding Calculate Mean by Row or Column, Arithmetic Mean Calculation, Nested List Indexing, Conditional Branching (If-Else), Row-wise Iteration, Column-wise Iteration, Linear Algebra, Programming Fundamentals, Data Structures, Numerical Computing, Statistical Foundations, Matrix Operations, List Manipulation, Conditional Programming, Iterative Algorithms, Descriptive Statistics.

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.