Remove use of len as it doesn't work with sparse matrices