C1_W4_Assignment

Hello,

I am doing the C1_W4 programming assignment and I am stuck on exercise 3.

I have the following:

### START CODE HERE ###
P = np.array([    
    [0, .75, .30, .75, .10],
    [.10, 0, .30, .05, .30],
    [.30, .12, 0, .10, .55],
    [.55, .05, .30, 0, .05],
    [.05, .08, .10, .10, 0]
]) 
X0 = np.array([[0], [0], [0], [1], [0]])
# Multiply matrix P and X_0 (matrix multiplication).
X1 = np.matmul(P,X0)

### END CODE HERE ###
print(sum(P))

When I run the test:

# Test your solution.
w4_unittest.test_matrix(P, X0, X1)
Wrong vector X1. Check if matrix multiplication was performed correctly.
 6  Tests passed
 1  Tests failed

I am not sure what I am doing wrong with the matrix multiplication for X1?

Any insight as to my mistake is greatly appreciated.

Hi, I am also getting the same error. Not sure what’s wrong with the result. Does the test expect to have specific number in the matrix P?


### START CODE HERE ###
P = np.array([    
    [0,     0.25,   0.35,   0.15,   0.35],
    [0.15,  0,      0.35,   0.05,   0.15],
    [0.30,  0.20,   0,      0.20,   0.20],
    [0.20,  0.10,   0.20,   0,      0.30],
    [0.35,  0.45,   0.10,   0.60,   0   ]
]) 
X0 = np.array([[0], [0], [0], [1], [0]])
# Multiply matrix P and X_0 (matrix multiplication).
​
​
X1 = P @ X0
​
print(X1.shape)
print(X1)
### END CODE HERE ###
print(sum(P))

This is the result I got:


Wrong vector X1. Check if matrix multiplication was performed correctly.
 6  Tests passed
 1  Tests failed

There is a hard coded P matrix in the unittest script which is compared with the P matrix we used in the code. Don’t know why they have this comparison.


def test_matrix(target_P, target_X0, target_X1):
    successful_cases = 0
    failed_cases = []

    test_cases = [
        {
            "name": "default_check",
            "expected": {
                "P": np.array(
                    [
                        [0, 0.75, 0.35, 0.25, 0.85],
                        [0.15, 0, 0.35, 0.25, 0.05],
                        [0.15, 0.15, 0, 0.25, 0.05],
                        [0.15, 0.05, 0.05, 0, 0.05],
                        [0.55, 0.05, 0.25, 0.25, 0],
                    ]
                ),
                "X0": np.array([[0], [0], [0], [1], [0]]),
            },
        },
    ]

Thanks for finding that out!

I am following this thread, I have the same error. Then I assume this is something that might need to be fixed on deeplearning.ai side

Thanks for finding that out! There is no way any one could come up with that specific matrix given the problem statement.

Very true, as the only logic defined is that the main diagonal should be 0 and the columns adds to 1.