resolving sparse matrix issue with len() function