numpy.where()函数
numpy.where(condition, x, y)
1.如果参数只有condition
if give condition only
return
使condition为True的元素的下标(以多个array元组的形式返回)
2.如果给出全部参数(condition,x, y)
if condition==true
return x
else
return y
Examples:
只给出了condition,则返回使condition为True的元素的下标,以array元组形式返回,第一个array代表每个非零元素的第一维(二维矩阵中可以理解为行),第二个array代表每个非零元素的第二维(二维矩阵中可以理解为列)。
给出了condition,x, y, 则有:如果condition为Ture, 返回x ,否则返回 y
一个小实例,返回list中的元素在len中的下标