资源简介

coursera的吴恩达的课编程练习所需的所需包和数据,可以方便学员自己在本地练习

资源截图

代码片段和文件信息

import numpy as np

def linear_forward_test_case():
    np.random.seed(1)
    “““
    X = np.array([[-1.02387576 1.12397796]
 [-1.62328545 0.64667545]
 [-1.74314104 -0.59664964]])
    W = np.array([[ 0.74505627 1.97611078 -1.24412333]])
    b = np.array([[1]])
    “““
    A = np.random.randn(32)
    W = np.random.randn(13)
    b = np.random.randn(11)
    
    return A W b

def linear_activation_forward_test_case():
    “““
    X = np.array([[-1.02387576 1.12397796]
 [-1.62328545 0.64667545]
 [-1.74314104 -0.59664964]])
    W = np.array([[ 0.74505627 1.97611078 -1.24412333]])
    b = 5
    “““
    np.random.seed(2)
    A_prev = np.random.randn(32)
    W = np.random.randn(13)
    b = np.random.randn(11)
    return A_prev W b

def L_model_forward_test_case():
    “““
    X = np.array([[-1.02387576 1.12397796]
 [-1.62328545 0.64667545]
 [-1.74314104 -0.59664964]])
    parameters = {‘W1‘: np.array([[ 1.62434536 -0.61175641 -0.52817175]
        [-1.07296862  0.86540763 -2.3015387 ]])
 ‘W2‘: np.array([[ 1.74481176 -0.7612069 ]])
 ‘b1‘: np.array([[ 0.]
        [ 0.]])
 ‘b2‘: np.array([[ 0.]])}
    “““
    np.random.seed(1)
    X = np.random.randn(42)
    W1 = np.random.randn(34)
    b1 = np.random.randn(31)
    W2 = np.random.randn(13)
    b2 = np.random.randn(11)
    parameters = {“W1“: W1
                  “b1“: b1
                  “W2“: W2
                  “b2“: b2}
    
    return X parameters

def compute_cost_test_case():
    Y = np.asarray([[1 1 1]])
    aL = np.array([[.8.90.4]])
    
    return Y aL

def linear_backward_test_case():
    “““
    z linear_cache = (np.array([[-0.8019545   3.85763489]]) (np.array([[-1.02387576  1.12397796]
       [-1.62328545  0.64667545]
       [-1.74314104 -0.59664964]]) np.array([[ 0.74505627  1.97611078 -1.24412333]]) np.array([[1]]))
    “““
    np.random.seed(1)
    dZ = np.random.randn(12)
    A = np.random.randn(32)
    W = np.random.randn(13)
    b = np.random.randn(11)
    linear_cache = (A W b)
    return dZ linear_cache

def linear_activation_backward_test_case():
    “““
    aL linear_activation_cache = (np.array([[ 3.1980455   7.85763489]]) ((np.array([[-1.02387576  1.12397796] [-1.62328545  0.64667545] [-1.74314104 -0.59664964]]) np.array([[ 0.74505627  1.97611078 -1.24412333]]) 5) np.array([[ 3.1980455   7.85763489]])))
    “““
    np.random.seed(2)
    dA = np.random.randn(12)
    A = np.random.randn(32)
    W = np.random.randn(13)
    b = np.random.randn(11)
    Z = np.random.randn(12)
    linear_cache = (A W b)
    activation_cache = Z
    linear_activation_cache = (linear_cache activation_cache)
    
    return dA linear_activation_cache

def L_model_backward_test_case():
    “““
    X = np.random.rand(32)
    Y = np.array([[1 1]])
    parameters = {‘W1‘: np.array([[ 1.78862847  0.43650985  0.09649747]]) ‘b1‘: np.array([[ 0.]])}

    aL caches = (np.array([[ 0.60298372  0.87182628]]) [((np.arr

评论

共有 条评论