np.where说明

四旋翼无人机数学模型推导 本周开始进行四旋翼无人机的学习工作,首先来进行四旋翼无人机的数学模型推导工作。。 四旋翼动力学数学模型 坐标变换 介绍四旋翼数学模型之前,首先引入坐标变换的概念,定义两个坐标系惯性坐标系{E},以及机体坐标系{B},惯性坐标系就相当于在地面建立的、静止不动的坐标系,也是我们操纵无人机所在的空间,而机体坐标系是建立于四旋翼机体之上,随着四旋翼姿态变换而变化,所以建立一种地面上的惯性坐标系与四旋翼机体坐标系之间的转换关系,就有这个必要。 对于惯性坐标系{E},以及机体坐标系{B},它们之间的转换关系 阅读详情

引用几个例子

>>> a = np.array([-1, -2, 0, 1, 2])
>>> np.where(a)
(array([0, 1, 3, 4]),)

只有input,后面没有指定条件,返回非0的元素

>>>a = np.arange(10)
>>>a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>>np.where(a < 5, a, 10*a)
array([ 0,  1,  2,  3,  4, 50, 60, 70, 80, 90])

有指定条件,等价为 if a的元素 < 5, 元素 =它本身, else 元素 = 10*它本身

>>> np.where([[True, False], [True, True]],
         [[1, 2], [3, 4]],
         [[9, 8], [7, 6]])
output:         
array([[1, 8],
       [3, 4]])

这里相当于一个2x2数组(T, F ; T, T), 其中" ; "表示换行,它后面跟的有两个2x2数组,分别对应了if T 条件 和else的条件。
具体来说,
如果第一行的(T, F)的元素为(T, T),它就等于(1, 2), 否则等于(9, 8)
现在第一个元素为T,就等于1, 第2个元素为F,就等于8。所以第一行返回(1, 8)
同理第二行。

再举个例子,

>>> b = np.array([[1,1],[2,3] ,[0.2,0.5]])
>>> b
array([[1. , 1. ],
       [2. , 3. ],
       [0.2, 0.5]])
>>> np.where(b)
output:
(array([0, 0, 1, 1, 2, 2]), array([0, 1, 0, 1, 0, 1]))

你肯定想说,为什么返回两个一维数组,这是什么意思。
首先,b是一个3x2数组,np.where要返回b中> 0的元素位置
位置包含了行坐标和列坐标,
那第一行就是行坐标,第2行就是列坐标,不信把它们拼在一起看一下

0, 0, 1, 1, 2, 2
0, 1, 0, 1, 0, 1

按列看,是不是坐标就是(0,0), (0, 1), (1, 0), … , (2,1)

把b改一下,把最后一个元素改为0

>>> b
array([[1. , 1. ],
       [2. , 3. ],
       [0.2, 0. ]])
>>> np.where(b)
output:
(array([0, 0, 1, 1, 2]), array([0, 1, 0, 1, 0]))

可以看到,最后一个元素的坐标没有了。

ABAP调用启信宝API 方法参数定义如下 源代码如下 method qxb_http_get. data:lv_url type string. "===============初始化=============================================== "获取http实例 cl_http_client=>create_by_destination( exporting destination = space importing 阅读详情

相关推荐

新手必看:LiteRadio 2c SE遥控器从开箱到飞行的完整指南(附常见问题解答)

本文为新手提供LiteRadio 2c SE遥控器的完整使用指南,涵盖从开箱到首飞的20个关键步骤。详细介绍了遥控器的功能设置、与无人机的对频技巧以及首飞注意事项,帮助用户快速掌握飞行控制,避免常见错误。特别适合无人机初学者阅读。

weixin_29209801的博客 388

numpy.where() 用法详解

numpy.where (condition[,x,y])numpy.where()有两种用法: 1. np.where(condition, x, y) 满足条件(condition),输出x,不满足输出y。 如果是一维数组,相当于[xv if c else yv for (c,xv,yv) in zip(condition,x,y)] >>> aa = np.a...

星之所望的博客 887

Android车载应用开发与分析(11)- 车载Android应用开发入门指南

将时间回退到2017年我大学刚毕业时,彼时移动互联网就已经开始退潮,各大个培训机构也纷纷停止了Android相关的培训,曾经热火朝天的应用开发从那时起,就开始走向下坡路,小程序以及众多跨平台框架也让市场对Android原生开发的需求逐年降低,市场需求的降低也造就了Android开发的面试变得史无前例的“卷”。 终于我在2019年选择离开了互联网,投身当时还不是非常火热的车载Android领域继续从事Android原生开发。而这一年中国首个外商独资的整车制造项目,“...

linkwj的博客 1万+

np.where()函数的用法

1.根据判断条件返回下标 d = np.array([[4,-6,7],[4,-5,6]]) e = np.where(d<0) #return (array([0, 1]), array([1, 1])) 2.根据判断条件返回制定值 a = 10 b = np.where(a > 0, 1.0, 0.0) print(b) #retuen 1.0 ``

qq_43790749的博客 3306

zemax双透镜公差分析

蒙特卡罗分析: 评估公差的整体影响,模拟过程中产生一系列随机的lens,满足指定的公差,然后再按照标准评估。公差分析,就是在设计了一个理想的系统后,想看看实际生产过程中如果产生公差(误差),系统会坏到什么程度,也就是光学性能受到多大影响。反灵敏度分析:分别对每个公差在性能方面的一个给定的最小允许减少量来计算公差,也就是限制了系统性能的变化,和灵敏度分析方向相反。灵敏度分析对每个公差单独求值,分别计算每个公差操作数的最大、最小、标准值(如上图)所有设计上可能的公差都列出来了。注意要固定透镜的口径。

fendoudecheng的博客 3224

《惠普工作站设置BIOS从U盘装系统》

惠普工作站设置BIOS 惠普工作站在做服务器时应用广泛,本文介绍下其BIOS开机自启动设置,附上图片,以供学习参考。 惠普工作站设置BIOS 启动步骤如下: 第一步:根据需要对BIOS进行更改,并保存 1.重启工作站按F10进入BIOS设置(也可以按ESC键选择进入BIOS设置的选项)。 图1 惠普工作站B...

istrangeboy&begin zero的博客 2万+

np.where函数

<1> np.where( condition ) 输入只有条件数组condition的话,返回的是满足条件的元素索引。 1)condition为一维数组,返回值out为一个一维数组索引组成的元组; 2)condition为二维数组,返回值out为两个一维数组组成的元组,第一个数组为dim=0(行)的索引,第二个数组为dim=1(列)的索引。 condition数组: condition二维数组可以来自于数据数组的比较得到。 if __name__=="__main__": x = np

YJYS_ZHX的博客 3320

从SAS接口到InfiniBand:一张图看懂数据中心硬件‘黑话’(SFF-8643/8644、QSFP112、NDR/HDR/EDR)

本文深入解析数据中心硬件术语,从SAS接口标准(SFF-8643/8644)到速率标识(NDR/HDR/EDR),帮助工程师快速理解关键性能指标。特别对比了PCIe卡规格(HHHL/FHHL)和光模块选择(QSFP112/OSFP),并探讨InfiniBand在高性能网络中的优势,为硬件选型提供实用指南。

weixin_32103009的博客 442

np.where()的使用方法

一篇不错的博客:https://blog.csdn.net/island1995/article/details/90200151 我在实践中使用 graph = np.zeros((h, w)) graph[np.where(label == 0)] = 1,对应的操作是在graph上进行的。所以label==0的索引位置变成了1,label != 0 的位置还是保持0,不适合我该部分的实...

lovebabyhai的博客 2304

HAL库移植实战:解决‘HAL_StatusTypeDef‘未定义报错的3个关键步骤

本文针对STM32开发中从标准库向HAL库移植时常见的'HAL_StatusTypeDef'未定义报错,提供了三个关键解决步骤:首先确保正确包含头文件入口,其次检查并配置模块使能宏,最后注意避免与标准库的同名结构体混用。文章通过实战案例解析了HAL库的模块化设计理念,帮助开发者高效解决混合编程中的编译问题。

book8的博客 219

KT148A语音芯片SOP外挂功放芯片8002D的说明_V1

KT148A语音芯片内置8欧姆0.5W的功放,所以一般的应用场景,播放一些提示音音量是足够的。但是有的需求还需要驱动更大的扬声器,实现更大的播放音量,这里我们给出解决方案。KT148A+HAA8002D的组合

qyvhome的博客 2169

np.where()用法解析

np.where(condition, x, y) 满足条件(condition),输出x,不满足输出y。 import numpy as np aa = np.arange(10) np.where(aa > 5,1,-1) array([-1, -1, -1, -1, -1, -1, 1, 1, 1, 1]) np.where(condition) 只有条件 (condition),没有x和y,则输出满足条件 (即非0) 元素的坐标 (等价于numpy.nonzero)。这里的坐.

Galen_xia的博客 1016

如何在MacBook上安装部署原生openclaw

本文介绍了在MacBook上安装OpenClaw的详细步骤:首先通过curl或国内镜像源安装nvm和Node.js(版本≥22),然后使用nvm安装Node.js 24并验证安装。接着通过脚本快速安装OpenClaw,完成安装后选择Qwen作为AI模型并进行OAuth认证。配置过程中可跳过联网搜索和Agent技能设置,最后选择Web界面作为呈现方式。安装完成后,系统会启动openclaw-gateway进程并打开Web界面,用户可通过简单的"hello"指令开始与AI对话。目前基础功能已

木简熙的博客 825

[转载]np.where()使用说明

转载自https://www.cnblogs.com/massquantity/p/8908859.html#4072620 numpy.where()有两种用法: 1. np.where(condition, x, y) 满足条件(condition),输出x,不满足输出y。如果是一维数组,相当于[xv if c else yv for (c,xv,yv) in zip(condi...

weixin_30825199的博客 108

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

总结了12个Numpy高级函数,完美解决数据处理,拿来即用!

总结了12个Numpy高级函数,用了的都说好!

数据分析与统计学之美 7389

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

python的np.where()的用法

a=[1,2,3,4,5,6,7,8] a=np.array(a) b=np.where((a>2)&(a<6)) print(b) #(array([2, 3, 4], dtype=int64),) 一定要将a转化为数组,否则会报错: ‘>’ not supported between instances of ‘list’ and ‘int’

qq_35706187的博客 460

np.where和random.binomial的理解

np.where////np.random.binomial

ZGP1234的博客 216

Python:获取array满足给定条件的元素的索引

使用np.argwhere import numpy as np a = np.array([1,2,3,4,5,6,1,2,3]) b = np.argwhere(a == 1) print(b) 输出: [[0] [6]] 使用np.where import numpy as np a = np.array([1,2,3,4,5,6,1,2,3]) b = np.wher...

DeniuHe的博客 9114

numpy.ma.masked_where:屏蔽满足条件的数组

屏蔽满足条件的数组内容,返回值为掩码数组。

chongbaikaishi的博客 628

python,使用np.where和box[:, 0]

用作自己的学习笔记,侵权删。

zhidian2020的博客 234

关于np.where(a>10),你知道怎么用吗?

从上面我们可以看到这个np.where返回的是位置信息。一维的就返回一维度,也就是那一个所在的位置。在原本的多目标轮廓匹配案例中得到的结果就是就是那个的左上角的坐标信息。二维的就返回那个的位置。这里用一个例子来讲明白。

weixin_73958875的博客 408

python分段函数编程例子_Python Numpy绘制分段函数示例

引出分段函数根据自变量的取值范围决定不同的计算方式,Numpy中提供了多种计算分段函数的方法。方便起见,在这里使用一个分段函数的例子:计算三角波形(例子取自张若愚的《Python科学计算》)三角波形具有周期性,因此我们只需要考虑0~1之间的这个范围就可以了,在这个范围里,又分了三个不同的表达式。最直观的自定义函数分段函数就是分类讨论嘛,只要针对不同的x值,选择范围,计算就可以了,因此:def tr...

weixin_39772352的博客 904

Numpy-6 数组的其他常用函数

本文介绍了NumPy库中数组的常用函数操作,主要包括三类功能:1)基本判断函数,包括比较运算(greater/less/equal)、逻辑运算(and/or/not/xor)和布尔运算(any/all);2)条件判断函数,详细讲解了where()和select()两种条件筛选方法;3)数组形状运算,包含数组拼接(concatenate)、拆分(split)和形状调整(reshape)三种操作。

qq_73979067的博客 505

学习笔记(01):Python数据清洗实战-Numpy常用数据清洗函数

本次课程主要以真实的电商数据为基础,通过Python详细的介绍了数据分析中的数据清洗阶段各种技巧和方法。

davcl的博客 203

Numpy之ndarray运算

ndarray运算1 逻辑运算2 通用判断函数3 np.where(三元运算符)4 统计运算4.1 统计指标4.2 案例:学生成绩统计运算 1 逻辑运算 # 生成10名同学,5门功课的数据 >>> score = np.random.randint(40, 100, (10, 5)) # 取出最后4名同学的成绩,用于逻辑判断 >>> test_score = score[6:, 0:5] # 逻辑判断, 如果成绩大于60就标记为True 否则为False >&

汪云辉的博客 271

笔记

1.np.less(arr1, arr2) arr1小于arr2 2.np.greater_equal(arr1,arr2)arr1大于等于arr2 3.np.logical_and(a>3,a<9)两个条件都满足就为true 4.np.where(cond,ndarray1,ndarray2)根据条件cond,选取ndarray1或者ndarray2,返回一个新的ndarray ...

qq_42146047的博客 117

【实战解析】np.where() 在数据清洗与条件替换中的高效应用

本文深入解析了NumPy库中np.where()函数在数据清洗与条件替换中的高效应用。通过实战案例展示了如何利用np.where()快速处理异常值、缺失值和条件分类,显著提升数据处理效率。文章还对比了向量化操作与传统循环的性能差异,揭示了np.where()在百万级数据量下速度提升50倍的底层优势,并提供了电商评论情感分析等真实场景的应用示范。

weixin_28465009的博客 130
上一篇: leetcode 991. Broken Calculator(坏掉的计算器)
下一篇: pytorch 矩阵运算巧求点之间的距离
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址