Problem with assignment. Python error or mine?
MarkA
someone at somewhere.invalid
Thu Dec 21 12:17:21 EST 2017
On Thu, 21 Dec 2017 07:05:33 -0800, rafaeltfreire wrote:
>From docs.python.org:
8.10. copy — Shallow and deep copy operations
Source code: Lib/copy.py
Assignment statements in Python do not copy objects, they create bindings
between a target and an object. For collections that are mutable or
contain mutable items, a copy is sometimes needed so one can change one
copy without changing the other. This module provides generic shallow and
deep copy operations (explained below)...
> Dear community, I am having the following problem when I am assigning
> the elements of a vector below a certain number to zero or any other
> value.
> I am creating a new variable but Python edits the root variable. Why?
>
> import numpy as np
>
> X=np.arange(1, 10000, 1) #root variable x1=X x1[x1<10000]=0
>
> print(X)
> Out[1]: array([ 0., 0., 0., ..., 0., 0., 0.])
>
> Why????????? It is supposed to be the original value Thank you for your
> time Rafael
--
MarkA
We hang petty theives, and appoint the great theives to public office
-- Aesop
More information about the Python-list
mailing list