C1_W2_Assignment exercise 4 syntax error

I continue to get a syntax error at line 7 .
It is probably me, but I seriously cannot figure out what is wrong with this.


A_ref = SwapRows(A_system, 0, 1)```

What happens if you remove the triple quote?

The three quotes are a mistake from the forum editor. They’re not actually there

The parser repeats the offending line and displays a little ‘arrow’ pointing at the earliest point in the line where the error was detected. The error is caused by (or at least detected at) the token preceding the arrow

emphasis in the original. Meaning the line in your printout is unlikely the culprit. Instead, a preceding line likely has a little too much of something or not enough of another.

Hello @matteo_cordaro is your issue solved now? If not please let me see a screenshot of the error message

Mismatched parentheses previous line

Btw that is what I meant when I wrote above a preceding line likely has a little too much of something or not enough of another

In this case, too many open paren (((( not enough close )))

Hello @matteo_cordaro I meant you share your error message but not your code, Please edit the post and delete the screenshot to avoid your account being flagged for posting answers

In meantime do as @ai_curious has told you, Add closing parentheses ‘)’ at the end of A_system

Hello, I can’t create a topic, so I post my problem here.

C1_W2_Assignment Exercise 4 Error:

My result turned out to be like this:
[[ 1. 2. -1. -1. 3.] [ 0. 1. 4. 3. 22.] [ 0. 0. 1. 3. 7.] [-0. -0. -0. 1. 1.]]

While the Expected Output are:

[[ 1 2 -1 -1 3]
[ 0 1 4 3 22]
[ 0 0 1 3 7]
[ 0 0 0 1 1]]

However, when I run the syntax “w2_unittest.test_augmented_to_ref(augmented_to_ref)”, it shows:


UFuncTypeError Traceback (most recent call last)
in
1 # Test your solution
----> 2 w2_unittest.test_augmented_to_ref(augmented_to_ref)

~/work/w2_unittest.py in test_augmented_to_ref(target)
342
343 for test_case in test_cases:
→ 344 result = target(test_case[“input”][“A”], test_case[“input”][“b”])
345
346 try:

in augmented_to_ref(A, b)
40
41 # multiply row 3 of the new matrix A_ref by -1/17
—> 42 A_ref = MultiplyRow(A_ref,3,-1/17)
43 ### END CODE HERE ###
44 return A_ref

in MultiplyRow(M, row_num, row_num_multiple)
5 # exchange row_num of the matrix M_new with its multiple by row_num_multiple
6 # Note: for simplicity, you can drop check if row_num_multiple has non-zero value, which makes the operation valid
----> 7 M_new[row_num] *= row_num_multiple
8 return M_new
9

UFuncTypeError: Cannot cast ufunc ‘multiply’ output from dtype(‘float64’) to dtype(‘int64’) with casting rule ‘same_kind’


How to solve it?

Hello @Shengkai_Chang Why are you unable to create a topic?

Your error message is indicating that you are trying to perform an operation that involves a float64 type to an int64 type and that numpy is unable to automatically convert the output to the desired int64 type.

When numpy performs arithmetic operations on arrays with different data types, it follows a set of casting rules to determine the data type of the output array. The ‘same_kind’ rule means that the output array should have the same data type as the input arrays. In this case, the inputs are of different types (float64 and int64) and the output cannot be cast to an int64 type.

I am not sure but you can try to convert the data types of the arrays before performing the operation maybe it will help solve the error. You can give it a try using astype() function like the following


a = np.array([1, 2, 3], dtype=np.int64)

b = a.astype(np.float64) 

Happy learning
Isaak

Same problem with my assignment, please help me fix it. I get syntax error even when I follow the rules given before that.

Hello @Iqra_Yaseen
Please post a screenshot of your error

I get error " A_ref " is not defined in exercise # 5. Even when I run all the code cells of notebook, I get the same error.

How have you defined your A_ref = ?
“A_ref” is not recognized as a variable/function, in your code. Have a look at it

All my code cell run don’t show any problem but when I submit the assignment grade show as 0 because A_ref is not defined. How can I solve this problem?

HI Isaak, I have ran the code and all looks good. Including the unit test for each section. However, when I submit my assignment to grade it grade me 0 with this message.
“There was a problem compiling the code from your notebook. Details:
name ‘A_ref’ is not defined” I can’t seem to figure out why. I thought it was an alignment issue with the function augmented_to_ref(A, b) where it returns the A_ref. I even tried type casting the value to "int’ - return A_ref.astype(int). But no luck. Appreciate if you can provide some guidance.

Similar issue with me as well. Each section unit test has pass and also the results match with the expected results. Graded as 0 after submission because of "Details:
name ‘A_ref’ is not defined”

Hello @hi_chi and @badwar
Please check whether you’ve run the A_ref cell?
and if it’s assigned a value? Also try grading your assignment using partial grading #grade-up-to-here
If all that fails, Please let me know

Screenshot 2023-06-07 at 6.09.55 PM

Hi Isaak,

I used the # grade-up-to-here and it shows that all is correct till Exercise 3. The error starts from exercise 4.

Failed test case: Object augmented_to_ref has incorrect type…
Expected:
<class ‘function’>,
but got:
<class ‘NoneType’>.

When I run each cell until the end one by one, all the cells are correct and pass the unit test till Exercise 6. Problems comes only when I submit the assignment.

I have been stuck at this for more than an hour. Not able to understand the syntax error. Please help.


HI @Kanav19

Welcome to the community.

Welcome to the community. I’m not sure, but it is possible that it is a indentation issue. Try to use spaces instead of tabs and run it again.

best regards
elirod