
    Write a function to sort medical scan layers based on their total tissue density values, where each layer is represented as a row of pixel intensities in ascending order of their sums. The sorted arrangement of tissue layers will help standardize the analysis of cross-sectional medical images for detecting potential abnormalities.
    

    
def sort_matrix(M):
    """
    Write a function to sort medical scan layers based on their total tissue density values, where each layer is represented as a row of pixel intensities in ascending order of their sums. The sorted arrangement of tissue layers will help standardize the analysis of cross-sectional medical images for detecting potential abnormalities.
    

    """
def sort_matrix(M):
    """
    Write a function to sort medical scan layers based on their total tissue density values, where each layer is represented as a row of pixel intensities in ascending order of their sums. The sorted arrangement of tissue layers will help standardize the analysis of cross-sectional medical images for detecting potential abnormalities.
    

    """
    result = sorted(M, key=sum)
    return result