# -*- coding: utf-8 -*-
"""
Created on Sat Aug 18 15:31:08 2018

@author: hp
"""

import numpy as np

def sigmoid(Z):
    A=1/(1+np.exp(-Z))
    cache = Z
    return A,cache

def sigmoid_backward(dA,cache):
    Z=cache
    s=1/(1+np.exp(-Z))
    dZ=dA*s*(1-s)
    
    assert(dZ.shape==Z.shape)
    
    return dZ

def relu(Z):
    A=np.maximum(0,Z)
    
    assert(A.shape==Z.shape)
    
    cache = Z
    return A,cache

def relu_backward(dA,cache):
    Z=cache
    dZ=np.array(dA,copy=True)# just converting dz to a correct object.
    
    dZ[Z<=0]=0
    assert(dZ.shape==Z.shape)
    return dZ
