nd.array.where
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 nd ious = 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.7
print(flag) ious = nd.where(flag,ious,y)
print(ious)
nd.array.where的更多相关文章
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
- ES5对Array增强的9个API
为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...
- JavaScript Array对象
介绍Js的Array 数组对象. 目录 1. 介绍:介绍 Array 数组对象的说明.定义方式以及属性. 2. 实例方法:介绍 Array 对象的实例方法:concat.every.filter.fo ...
- 了解PHP中的Array数组和foreach
1. 了解数组 PHP 中的数组实际上是一个有序映射.映射是一种把 values 关联到 keys 的类型.详细的解释可参见:PHP.net中的Array数组 . 2.例子:一般的数组 这里,我 ...
- 关于面试题 Array.indexof() 方法的实现及思考
这是我在面试大公司时碰到的一个笔试题,当时自己云里雾里的胡写了一番,回头也曾思考过,最终没实现也就不了了之了. 昨天看到有网友说面试中也碰到过这个问题,我就重新思考了这个问题的实现方法. 对于想进大公 ...
- javascript之活灵活现的Array
前言 就如同标题一样,这篇文章将会灵活的运行Array对象的一些方法来实现看上去较复杂的应用. 大家都知道Array实例有这四个方法:push.pop.shift.unshift.大家也都知道 pus ...
- 5.2 Array类型的方法汇总
所有对象都具有toString(),toLocaleString(),valueOf()方法. 1.数组转化为字符串 toString(),toLocaleString() ,数组调用这些方法,则返回 ...
- OpenGL ES: Array Texture初体验
[TOC] Array Texture这个东西的意思是,一个纹理对象,可以存储不止一张图片信息,就是说是是一个数组,每个元素都是一张图片.这样免了频繁地去切换当前需要bind的纹理,而且可以节省系统资 ...
- Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...
- C++ std::array
std::array template < class T, size_t N > class array; Code Example #include <iostream> ...
随机推荐
- JavaScript迭代
定义: 指的是按照某种顺序逐个访问列表中的每一项. 迭代在数学中的定义: 在循环的基础上, 每一次循环, 都比上一次更为接近结果. 循环定义:指的是在满足条件的情况下,重复执行同一段代码. 迭代方法: ...
- java线程总结2--wait/notify(all)/sleep以及中断概念
上一篇关于线程的博客简单梳理了一下多线程的一些基本概念,今天这篇博客再进行多线程编程中一些核心的方法进行简单的梳理和总结,主要是wait,sleep和notify方法以及中断的概念 一.中断概念. 在 ...
- 17、多线程 (Thread、线程创建、线程池)
进程概念 *A:进程概念 *a:进程:进程指正在运行的程序.确切的来说,当一个程序进入内存运行, 即变成一个进程,进程是处于运行过程中的程序,并且具有一定独立功能. 线程的概念 *A:线程的概念 *a ...
- Spring------约束导入和application.xml的引入方式
1.spring约束的导入 2.SSH常用约束 3.application.xml的引入方式 <1.通过ClassPathXmlApplicationContext引入配置文件applicati ...
- CODEFORCES 429B 动态规划
http://codeforces.com/problemset/problem/429/B 可以参考这篇文章: http://blog.csdn.net/pure_lady/article/deta ...
- Linux 新手入门常用命令
1,增加用户:useradd mylinux passwd mylinux 添加你的用户密码 2,切换用户: su otheruser (注意这种切换方式只是临时的,本质工作目录还在原来的用户目录 ...
- 初识WCF2
参照: http://blog.csdn.net/songyefei/article/details/7371571 在上一篇中,我们在一个控制台应用程序中编写了一个简单的WCF服务并承载了它.先回顾 ...
- javascript animation lib greensock gsap介绍
一般前台做动画有以下几种方式: 1. 简单的css transition动画; 2. css animation动画 3. javascript库动画 一般来说css html5动画只适用于简单的形变 ...
- Exchange 接收连接器(Client、Default)区别,OUtlook实际测试
CAS就是接收连接器(110,995): Server Config--Client Access:POP3 and IMAP4:POP3设置 HUB就是发送连接器(25,587) Server Co ...
- Spring学习---Spring中利用jackson进行JSON转换
Spring中利用jackson进行JSON转换 import java.util.List; import com.fasterxml.jackson.core.JsonProcessingExce ...