Python notes, python

Source: Internet
Author: User

Python notes, python

# Numpy. argmax (a, axis = None, out = None)
Returns the index with the maximum value of axis along the axis.

Parameters:
A:Array_like 
Array
Axis:Int, optional 
By default, the index is a tiled array, otherwise it is along the specified axis.
Out:Array, optional 
If provided, the results are inserted into the array in the appropriate shape and type.
Returns:
Index_array:Ndarray of ints 
Index Array. It has the same shape as a. shape, where axis is removed.
Example:

>>> A = np. arange (6 ). reshape (2, 3) >>> aarray ([[0, 1, 2], [3, 4, 5]) >>> np. argmax (a) 5 >>> np. argmax (a, axis = 0) #0 represents the array ([1, 1, 1])> np. argmax (a, axis = 1) #1 represents the row array ([2, 2]) >>>>> B = np. arange (6) >>> B [1] = 5 >>> barray ([0, 5, 2, 3, 4, 5]) >>> np. argmax (B) # returns the Index 1 of the maximum value that appears for the first time.

# Numpy. max (a, axis = None, out = None)

Similar to argmax, but the returned value is the largest element rather than the index.

 

# Tf. boolean_mask (a, B)

A function in tensorflow is often used for target detection (YOLO.

B is generally an n-dimensional vector of the bool type. If a. shape = [3, 3] B. shape = [3, 3]

ThenTf. boolean_mask (a, B)Only the part of the (m dimension) matrix that is equal to the "True" element in B is retained, and the result is expanded to the m-1 dimension.

For example, the YOLO algorithm returns the location information (bx, by, bh, bw) of all detected targets (vehicles, pedestrians, traffic signs, etc)

a = np.random.randn(3, 3,3)b = np.max(a,-1)c=  b >0.5print("a="+str(a))print("b="+str(b))print("c="+str(c))with tf.Session() as sess:    d=tf.boolean_mask(a,c)print("d="+str(d.eval(session=sess)))
>>
a=[[[-1.25508127  1.76972539  0.21302597]  [-0.2757053  -0.28133549 -0.50394556]  [-0.70784415  0.52658374 -3.04217963]] [[ 0.63942957 -0.76669861 -0.2002611 ]  [-0.38026374  0.42007134 -1.08306957]  [ 0.30786828  1.80906798 -0.44145949]] [[ 0.22965498 -0.23677034  0.24160667]  [ 0.3967085   1.70004822 -0.19343556]  [ 0.18405488 -0.95646895 -0.5863234 ]]]b=[[ 1.76972539 -0.2757053   0.52658374] [ 0.63942957  0.42007134  1.80906798] [ 0.24160667  1.70004822  0.18405488]]c=[[ True False  True] [ True False  True] [False  True False]]d=[[-1.25508127  1.76972539  0.21302597] [-0.70784415  0.52658374 -3.04217963] [ 0.63942957 -0.76669861 -0.2002611 ] [ 0.30786828  1.80906798 -0.44145949] [ 0.3967085   1.70004822 -0.19343556]]
 

 

 

 

 

 

 

 

 

 

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.