vector = Numpy.array ([5, ten, +]) equal_to_ten_or_five = (vector = = 10) | (vector = = 5) vector[equal_to_ten_or_five] = 50print (vector)
The first time to see this when a face confused, and then analyzed the next to understand the following record, convenient next time to see
The first line of analysis:
Results 5, 10, 15, 20
The second line of analysis:
Vector = = 10 The array and the value of the pair get the result is that each element and this number comparison generates the corresponding bool array here we know the result is [flase,true,flase,flase]
Vector = = 5 is [true,flase,flase,flase]
Then proceed or ' | ' The operation gets [True,true,flase,flase]
When two arrays are performed or are operands, the elements or elements of the array are directly the same ordinal and then the new array is obtained (following the rules f| F =f,f| T=t,t| T=T)
At this time equal_to_ten_or_five is equal to [true,true,flase,flase]
The third line analyzes:
The vector[equal_to_ten_or_five]=50 will give a copy equal to True to 50 of the other invariant that is at this time
Vector equals [50,50,15,20]
Replication issues in the Python numpy array