Я написал очень простой код на языке Python.Это странное поведение ...
from numpy import *
# generate 2 array with 15 random int between 1 and 50
pile = random.randint(1, 50, 15)
pile2 = copy(pile)
print("*** pile2",type(pile2),pile2)
print("tab with fixed values ")
tmp2=array([155,156,157,158,159])
print("tmp2",type(tmp2),tmp2)
pile2[:5]=tmp2
print("pile2",type(pile2),pile2)
print("*** pile",type(pile),pile)
print("flip a part of pile and put in an array")
tmp=pile[4::-1]
print("tmp",type(tmp),tmp)
pile[:5]=tmp
print("pile",type(pile),pile)
Когда я запускаю этот скрипт, он возвращает:
*** pile2 <class 'numpy.ndarray'> [20 23 29 31 8 29 2 44 46 17 11 47 29 43 10]
tab with fixed values
tmp2 <class 'numpy.ndarray'> [155 156 157 158 159]
pile2 <class 'numpy.ndarray'> [155 156 157 158 159 29 2 44 46 17 11 47 29 43 10]
Хорошо!Pill2 становится чем-то вроде «tmp2 [] и pile2 [6 ::]», но для второго ...
*** pile <class 'numpy.ndarray'> [20 23 29 31 8 29 2 44 46 17 11 47 29 43 10]
flip a part of pile and put in an array
tmp <class 'numpy.ndarray'> [ 8 31 29 23 20]
pile <class 'numpy.ndarray'> [ 8 31 29 31 8 29 2 44 46 17 11 47 29 43 10]
tmp [ 8 31 29 23 20 ]
куча [ 8 31 29 31 8 29 2 44 46 17 11 47 29 43 10]
О!Есть проблема с назначением!Что происходит?