当前位置:网站首页>Numpy: element selection of matrix
Numpy: element selection of matrix
2022-07-23 13:11:00 【Ling Xianwen】
>>> a = np.random.random((3,4))
>>> a
array([[0.890582 , 0.43671675, 0.19531267, 0.13555252],
[0.17254557, 0.3088476 , 0.36916878, 0.81551741],
[0.31869139, 0.16168486, 0.58004271, 0.4279148 ]])
>>> a.nonzero()
(array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2]), array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]))
>>> a[a.nonzero()] ## Method 1 , Use matrix to select
array([0.890582 , 0.43671675, 0.19531267, 0.13555252, 0.17254557,
0.3088476 , 0.36916878, 0.81551741, 0.31869139, 0.16168486,
0.58004271, 0.4279148 ])
>>> a
array([[0.890582 , 0.43671675, 0.19531267, 0.13555252],
[0.17254557, 0.3088476 , 0.36916878, 0.81551741],
[0.31869139, 0.16168486, 0.58004271, 0.4279148 ]])
>>> a[1,1] ## Method 2
0.3088475978138986
>>> a[1][1] ## Method 3
0.3088475978138986
>>> a[np.array([[False,False,False,False],[True,True,True,True,],
[False,False,False,False]])]
array([0.72159605, 0.90488492, 0.60745105, 0.20538722]) ## Method four 边栏推荐
猜你喜欢

STP configuration instance learning record

FTP configuration instance learning record

Plug ins used by Jenkins

Redis如何实现持久化?详细讲解RDB的三种触发机制及其优缺点,带你快速掌握RDB

Quick solution: xshell can't drag into folders or software packages

Secret key remote login server to realize secret free login

TI单芯片毫米波雷达代码走读(二十五)—— 角度维(3D)处理流程

Record a reptile question bank

MySQL----复合查询 外连接

OpenCV图像处理(下) 边缘检测+模板匹配+霍夫变换
随机推荐
时间复杂度总结(Ο是渐进上界,Ω是渐进下界,p,np,np-hard,NPC问题)
TI单芯片毫米波雷达xWR1642硬件架构研究
Offer II 094. Minimum palindrome segmentation
Cortex-a series processor
Matplotlib-实现常见概率分布
TI单芯片毫米波雷达代码走读(二十五)—— 角度维(3D)处理流程
Signal integrity (SI) power integrity (PI) learning notes (32) power distribution network (4)
力扣 729. 我的日程安排表 I
TI单芯片毫米波雷达1642代码走读(〇)——总纲
快速解决:Xshell拖不進去文件夾或者軟件包的問題
User and group management, file permissions
Real questions required for Niuke interview [algorithm] summary of high-frequency TOP200 questions
常见的cmd命令快速打开程序
国信证券软件开户是安全吗?信息会不会泄露?
2020-09-22
ACL——net
Signal integrity (SI) power integrity (PI) learning notes (XXXI) power distribution network (III)
HCIA----02
Solution rapide: xshell ne peut pas glisser dans un dossier ou un paquet
SAR成像之点目标仿真(三)—— 仿真结果分析