Replication issues in the Python numpy array

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.