The documentation at : https://numpy.org/doc/stable/user/basics.indexing.html?highlight=slice does say that slicing creates a view into the original, and not a new object. So it isn't a bug - it is entirely expected behaviour To Quote :
NumPy slicing creates a view https://numpy.org/doc/stable/glossary.html#term-view instead of a copy as in the case ofbuilt-in Python sequences such as string, tuple and list.Care must be taken when extractinga small portion from a large array which becomes useless after theextraction, because the small portion extracted contains a referenceto the large original array whose memory will not be released untilall arrays derived from it are garbage-collected. In such cases anexplicit copy() is recommended.
------ Original Message ------ From: "Leon fevang-gunn" email@example.com To: firstname.lastname@example.org Sent: Monday, 18 Jul, 22 At 15:59 Subject: [docs] Suspected bug
So I managed to fix it, but I think I had an experience with a bug... It seems that a slice of a numpy array gave me some trouble. Only after redefining the slice as a numpy array would the code run as normal again. In other words:
zk = np.array(list1)
zk2 = zk[a:b]
zk = np.array(list1) zk2 = np.array(zk[a:b])
I also checked and it does say that a slice of an array should be an array:
in: zk[a:b] out: arra(list1[a:b])
The problem was that it would link the two variables zk and zk2 together:
zk = array1
zk2 = array1[a:b]
When i changed zk2 to a different value, the corresponding element, zk[a], also changes. So for example:
zk = np.array([1,2,3,4,5]) zk2 = np.array(zk[1:4])
in: zk_2 = 0
out: array([1,0,3,4,5]) array([0,3,4])
- zk is read in from a .csv file using pandas.
- I am using Spyder/Anaconda - When i change a value of zk_2 in the command window, zk remains the same
Allright, thought I would let someone know. Let me know if you need additional information.
Kind regards, Leon
_______________________________________________ docs mailing list -- email@example.com To unsubscribe send an email to firstname.lastname@example.org https://mail.python.org/mailman3/lists/docs.python.org/ https://mail.python.org/mailman3/lists/docs.python.org/ Member address: email@example.com
-- <br>Anthony Flury<br>firstname.lastname@example.org