The Comparison Between Python list and NumPy. ndarry slice is described in detail,
Differences between Python list and NumPy. ndarry slices
Instance code:
# List slices return non-original data. Modifications to new data will not affect the original data In [45]: list1 = [1, 2, 3, 4, 5] In [46]: list2 = list1 [: 3] In [47]: list2Out [47]: [1, 2, 3] In [49]: list2 [1] = 1999 # original data is not changed In [50]: list1Out [50]: [1, 2, 3, 4, 5] In [51]: list2Out [51]: [1, 1999, 3] # And NumPy. the ndarry slice returns the original data In [52]: arr = np. array ([1, 2, 3, 4, 5]) In [53]: arrOut [53]: array ([1, 2, 3, 4, 5]) in [54]: arr1 = arr [: 3] In [55]: arr1Out [55]: array ([1, 2, 3]) In [56]: arr1 [0] = 989In [57]: arr1Out [57]: array ([989, 2, 3]) # modify the original data In [58]: arrOut [58]: array ([989, 2, 3, 4, 5]) # to obtain a copy of the original data, you can use copy () In [59]: arr2 = arr [: 3]. copy () In [60]: arr2Out [60]: array ([989, 2, 3]) In [61]: arr2 [1] = 99282In [62]: arr2Out [62]: array ([989,992 82, 3]) # The original data is not modified In [63]: arrOut [63]: array ([989, 2, 3, 4, 5])
The above are Python list and NumPy. explanation of the differences between ndarry slices. If you have any questions, please leave a message or leave a message to the community on this site. Thank you for reading this article and hope it will help you. Thank you for your support for this site!