博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nd.array.where
阅读量:4982 次
发布时间:2019-06-12

本文共 1420 字,大约阅读时间需要 4 分钟。

http://mxnet.apache.org/api/python/ndarray/ndarray.html#mxnet.ndarray.where

Return the elements, either from x or y, depending on the condition.

Given three ndarrays, condition, x, and y, return an ndarray with the elements from x or y, depending on the elements from condition are true or false. x and y must have the same shape. If condition has the same shape as x, each element in the output array is from x if the corresponding element in the condition is true, and from y if false.

If condition does not have the same shape as x, it must be a 1D array whose size is the same as x’s first dimension size. Each row of the output array is from x’s row if the corresponding element from condition is true, and from y’s row if false.

Note that all non-zero values are interpreted as True in condition.

x = [[1, 2], [3, 4]]y = [[5, 6], [7, 8]]cond = [[0, 1], [-1, 0]]where(cond, x, y) = [[5, 2], [3, 8]]csr_cond = cast_storage(cond, 'csr')where(csr_cond, x, y) = [[5, 2], [3, 8]]

X,Y必须同样形状,然后条件可以为同样形状,也可以是一维的;条件为0,才为Y,否则正数,负数都为X

from mxnet import ndious = nd.array([[0.1,0.3,0.3],[0.9,0.4,0.01],[0,0.55,2],[0.56,0.77,3],[0.9,0.73,4]])print(ious)label = [0. ,1., 1.]print(label)flag = nd.ones_like(ious)y = nd.full(ious.shape,0.5)for i, hard in enumerate(label):    if hard == 1.0:        flag[:,i] = ious[:,i] < 0.7print(flag)ious = nd.where(flag,ious,y)print(ious)

 

 

 

 

 

转载于:https://www.cnblogs.com/TreeDream/p/10209902.html

你可能感兴趣的文章
LOJ#565. 「LibreOJ Round #10」mathematican 的二进制 分治,FFT,概率期望
查看>>
C# 集合
查看>>
lucene学习笔记、资料
查看>>
js获取和设置DOM样式函数cssStyle(类似于jquery的$(elem).css())
查看>>
Agc011_F Train Service Planning
查看>>
三个问题
查看>>
一对一双向外键关联
查看>>
EL表达式概述
查看>>
javascript面向对象学习笔记(一)——继承
查看>>
python调试
查看>>
Selenium3+Python3_02:元素定位
查看>>
SpringMVC中的拦截器
查看>>
【转】如何将ACCESS数据库后缀名accdb改为mdb
查看>>
Debug : array type has incomplete element type
查看>>
代码腐化之路
查看>>
InnoDB 主键的选择:自增ID & 业务ID
查看>>
联系人数据库设计之ContactsTransaction
查看>>
如何制作一款HTML5 RPG游戏引擎——第四篇,情景对话
查看>>
无参函数的调用
查看>>
【记录】GIT 常用命令记录
查看>>