## 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'}