Reshapes arrays of ranks not in {1, 2, 4}

def _reshape_irregular_array(self, array, section_height, image_width):
    '''Reshapes arrays of ranks not in {1, 2, 4}
    '''
    section_area = section_height * image_width
    flattened_array = np.ravel(array)

    if not self.config['show_all']:
      flattened_array = flattened_array[:int(section_area/MIN_SQUARE_SIZE)]

    cell_count = np.prod(flattened_array.shape)
    cell_area = section_area / cell_count

    cell_side_length = max(1, floor(sqrt(cell_area)))
    row_count = max(1, int(section_height / cell_side_length))
    col_count = int(cell_count / row_count)

    # Reshape the truncated array so that it has the same aspect ratio as
    # the section.

    # Truncate whatever remaining values there are that don't fit. Hopefully
    # it doesn't matter that the last few (< section count) aren't there.
    section = np.reshape(flattened_array[:row_count * col_count],
                         (row_count, col_count))

    return section