def trim_zeros(arr):
    """
    Trims rows/columns/planes of all zeros from an array. It is assumed that the array is
    symmetrical in all directions.
    """
    slices = (slice(1, -1),)*arr.ndim
    while arr.size and (arr[0] == 0).all():
        arr = arr[slices]
    return arr