ó
ž÷Xc           @@  sA   d  Z  d d l m Z d d l Z d d  Z d d d  Z d S(   s   Numpy-related utilities.i    (   t   absolute_importNc         C@  sv   t  j |  d d j   }  | s7 t  j |   d } n  |  j d } t  j | | f  } d | t  j |  |  f <| S(   sW  Converts a class vector (integers) to binary class matrix.

    E.g. for use with categorical_crossentropy.

    # Arguments
        y: class vector to be converted into a matrix
            (integers from 0 to num_classes).
        num_classes: total number of classes.

    # Returns
        A binary matrix representation of the input.
    t   dtypet   inti   i    (   t   npt   arrayt   ravelt   maxt   shapet   zerost   arange(   t   yt   num_classest   nt   categorical(    (    s3   /tmp/pip-build-isqEY4/keras/keras/utils/np_utils.pyt   to_categorical   s    i˙˙˙˙i   c         C@  sE   t  j t  j j |  | |   } d | | d k <|  t  j | |  S(   sń   Normalizes a Numpy array.

    # Arguments
        x: Numpy array to normalize.
        axis: axis along which to normalize.
        order: Normalization order (e.g. 2 for L2 norm).

    # Returns
        A normalized copy of the array.
    i   i    (   R   t
   atleast_1dt   linalgt   normt   expand_dims(   t   xt   axist   ordert   l2(    (    s3   /tmp/pip-build-isqEY4/keras/keras/utils/np_utils.pyt	   normalize   s    !(   t   __doc__t
   __future__R    t   numpyR   t   NoneR   R   (    (    (    s3   /tmp/pip-build-isqEY4/keras/keras/utils/np_utils.pyt   <module>   s   