I am a data scientist working on time series forecasting (using R and Python 3) at the London Ambulance Service NHS Trust. I earned my PhD in cognitive neuroscience at the University of Glasgow working with fmri data and neural networks. I favour linux machines, and working in the terminal with Vim as my editor of choice.
A matrix is 'square' if it has the same number of rows as it does columns:
This is extremely simple:
If the matrix is not square, then it must either have more columns than rows (wide) or have more rows than columns (tall). We make a couple of methods to test those cases too:
We loop over each element in the upper triangular region and if we find a non-zero we return False, otherwise we return True:
Here we simply call the is_lower_tri method on the transposed matrix:
If the matrix qualifies as both lower and upper, then it must be diagonal. Therefore we use the previous two methods like so:
We loop over two ranges - one being the number of rows/columns, and the other being one less than that (since we don't need to check diagonal entries). If we find any $a_{ij} \neq a_{ji}$, we return False, otherwise we return True:
< The Mat(rix) Class, generation, and printing
back to project main page
back to home