+5 votes
in Programming Languages by (74.2k points)

I am using deepcopy() function to make a copy of the original variable, but the code is giving an error. What is wrong in the following code:

orig_X_bal, orig_y_bal = deepcopy(X_bal, y_bal)     # keep a copy

orig_X_bal, orig_y_bal = deepcopy(X_bal, y_bal)     # keep a copy

  File "/usr/lib64/python3.6/copy.py", line 142, in deepcopy

    y = memo.get(d, _nil)

AttributeError: 'numpy.ndarray' object has no attribute 'get'

1 Answer

+2 votes
by (349k points)
selected by
 
Best answer

There is a syntax error in your code. You are passing two arguments to the function deepcopy(). As you are trying to create a copy of X_val and y_val, you should use two deepcopy() functions.

Make the following change in your code and it will work.

From

orig_X_bal, orig_y_bal = deepcopy(X_bal, y_bal)

to

orig_X_bal, orig_y_bal = deepcopy(X_bal), deepcopy(y_bal)


...