def array_to_img(x, dim_ordering=(<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>), scale=True):
<EOL>x = x.transpose(dim_ordering)<EOL>if scale:<EOL><INDENT>x += max(-np.min(x), <NUM_LIT:0>)<EOL>x_max = np.max(x)<EOL>if x_max != <NUM_LIT:0>:<EOL><INDENT>x = x / x_max<EOL><DEDENT>x *= <NUM_LIT:255><EOL><DEDENT>if x.shape[<NUM_LIT:2>] == <NUM_LIT:3>:<EOL><INDENT>return PIL.Image.fromarray(x.astype('<STR_LIT>'), '<STR_LIT>')<EOL><DEDENT>elif x.shape[<NUM_LIT:2>] == <NUM_LIT:1>:<EOL><INDENT>return PIL.Image.fromarray(x[:, :, <NUM_LIT:0>].astype('<STR_LIT>'), '<STR_LIT:L>')<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>', x.shape[<NUM_LIT:2>])<EOL><DEDENT>
Converts a numpy array to PIL image object (uint8 format).

    Parameters
    ----------
    x : numpy.array
        An image with dimension of 3 and channels of 1 or 3.
    dim_ordering : tuple of 3 int
        Index of row, col and channel, default (0, 1, 2), for theano (1, 2, 0).
    scale : boolean
        If True, converts image to [0, 255] from any range of value like [-1, 2]. Default is True.

    Returns
    -------
    PIL.image
        An image.

    References
    -----------
    `PIL Image.fromarray <http://pillow.readthedocs.io/en/3.1.x/reference/Image.html?highlight=fromarray>`__