0

In jupyter notebook with python when i am changing the array value which is copy of the other array, it will affect on original array to.which is not convenient to use for me.

The below code i've tried on my jupyter notebook and i am changing the value of arr_temp[1] array.But it will affect to the original numpy array .

import numpy as np
array = np.array([1,5,6,7,8,94])
array[4:6]
arr_temp = array[4:6]
arr_temp[1]=100
array

I expect array([ 1, 5, 6, 7, 8, 94]) but i got values are array([ 1, 5, 6, 7, 8, 100]).

1 Answer 1

4

Try using arr_temp = array[4:6].copy(). You should always use copy() when you want to make changes to a subset of your data, otherwise python will see it as a slice and change the new and the original object.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.