## numpy.argmax(a, axis=None, out=None)
返回沿軸axis最大值的索引。python
Parameters:
a : array_like
數組
axis : int, 可選
默認狀況下,索引的是平鋪的數組,不然沿指定的軸。
out : array, 可選
若是提供,結果以合適的形狀和類型被插入到此數組中。
Returns:
index_array : ndarray of ints
索引數組。它具備與a.shape相同的形狀,其中axis被移除。
例子:算法
>>> a = np.arange(6).reshape(2,3)
>>> a array([[0, 1, 2], [3, 4, 5]]) >>> np.argmax(a) 5 >>> np.argmax(a, axis=0)#0表明列 array([1, 1, 1]) >>> np.argmax(a, axis=1)#1表明行 array([2, 2]) >>> >>> b = np.arange(6) >>> b[1] = 5 >>> b array([0, 5, 2, 3, 4, 5]) >>> np.argmax(b) # 只返回第一次出現的最大值的索引 1
## numpy.max(a, axis=None, out=None) 數組
與argmax相似,但返回值爲最大元素而非索引。session
## tf.boolean_mask(a,b)dom
tensorflow 裏的一個函數,在作目標檢測(YOLO)時經常用到。函數
其中b通常是bool型的n維向量,若a.shape=[3,3,3] b.shape=[3,3] 測試
則 tf.boolean_mask(a,b) 將使a (m維)矩陣僅保留與b中「True」元素同下標的部分,並將結果展開到m-1維。spa
例:應用在YOLO算法中返回全部檢測到的各種目標(車輛、行人、交通標誌等)的位置信息(bx,by,bh,bw).net
a = np.random.randn(3, 3,3)
b = np.max(a,-1) c= b >0.5 print("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]]
##Erest
enumerate:
list1 = ["這", "是", "一個", "測試"]
for i in range (len(list1)): print i ,list1[i]
list1 = ["這", "是", "一個", "測試"] for index, item in enumerate(list1): print index, item >>> 0 這 1 是 2 一個 3 測試
## L
lower: 返回小寫字母
def lower(self): # real signature unknown; restored from __doc__
"""
B.lower() -> copy of B
Return a copy of B with all ASCII characters converted to lowercase.
"""
pass
## O
os.path.join()函數
語法: os.path.join(path1[,path2[,......]])
返回值:將多個路徑組合後返回
注:第一個絕對路徑以前的參數將被忽略
## S
set() 函數:返回對象的一個集合
例如: set('boy')
--> {'b','o','y'}
set(['class1', 'class2', 'class1'])
->> {'class1', 'class2'}