Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

replace values in Numpy array

Hi experts.

Im trying to replace some values in a Numpy array. I wanna conserv the unchancge array too.

sage: N=np.array([[1,2,3],[4,5,6],[8,9,7]])

I call K the new array (with some values repaced):

sage: K=N sage: K array([[1, 2, 3], [4, 5, 6], [8, 9, 7]])

sage: K[1,2]=9

sage: K array([[1, 2, 3], [4, 5, 9], [8, 9, 7]])

But here is the problem: the original array is changed too!!

sage: N array([[1, 2, 3], [4, 5, 9], [8, 9, 7]])

How can I do for change only the array K (and conserv without change the original array N)?

Waiting for your answers.

Thanks a lot!

click to hide/show revision 2
fix typos, indent code

replace values in Numpy array

Hi experts.

Im I'm trying to replace some values in a Numpy array. I wanna conserv the unchancge conserve the unchanged array too.

sage: N=np.array([[1,2,3],[4,5,6],[8,9,7]])

sage: import numpy as np
sage: N = np.array([[1,2,3],[4,5,6],[8,9,7]])

I call K the new array (with some values repaced):

sage: K=N

sage: K = N
sage: K
array([[1, 2, 3],
       [4, 5, 6],
       [8, 9, 7]])

sage: K[1,2]=9

7]]) sage: K[1,2] = 9 sage: K array([[1, 2, 3], [4, 5, 9], [8, 9, 7]])

7]])

But here is the problem: the original array is changed too!!

sage: N
array([[1, 2, 3],
       [4, 5, 9],
       [8, 9, 7]])

7]])

How can I do for change only the array K (and conserv conserve without change the original array N)?

Waiting for your answers.

Thanks a lot!