Path: blob/main/a2/utils/__pycache__/utils.cpython-39.pyc
1003 views
a ��c � @ s d dl Zdd� Zdd� ZdS )� Nc C s8 | j d }| t�tj| d dd���|df�d } | S )zx Row normalization function Implement a function that normalizes each row of a matrix to have unit length. r � � ��axisg����KH�9)�shape�np�sqrt�sum�reshape)�x�N� r �=/Users/yimingwang/Desktop/cs224n/assignment/a2/utils/utils.py� normalizeRows s *r c C s� | j }t| j �dkrltj| dd�}| |�| j d df�8 } t�| �} tj| dd�}| |�| j d df� } n.t�| �}| |8 } t�| �} t�| �}| | } | j |ks�J �| S )a> Compute the softmax function for each row of the input x. It is crucial that this function is optimized for speed because it will be used frequently in later code. Arguments: x -- A D dimensional vector or N x D dimensional numpy matrix. Return: x -- You are allowed to modify x in-place r r r )r �lenr �maxr �expr )r � orig_shape�tmpr r r �softmax s r )�numpyr r r r r r r �<module> s