当前位置:网站首页>numpy:矩阵的元素选取
numpy:矩阵的元素选取
2022-07-23 05:48:00 【凌贤文】
>>> 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()] ##方法一,使用矩阵去选择
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] ##方法二
0.3088475978138986
>>> a[1][1] ##方法三
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]) ##方法四边栏推荐
- Rk3588 compilation problem set
- C randomly generate a score to judge its grade (excellent, good, medium, poor, failed)
- Gameframework:resource loading, resource loading, dependency loading, task pool, object pool, reference count
- 2020-09-22
- Learning diary - (routing and switching technology) network address translation NAT Technology
- Build FRPC client in NAS [super brainless]
- Learning diary - (routing and switching technology) OSPF Protocol
- SAR成像之点目标仿真(二)—— Matlab仿真
- 平方根立方根
- TI单芯片毫米波雷达代码走读(二十五)—— 角度维(3D)处理流程
猜你喜欢

STP configuration instance learning record

平方根立方根

秘钥远程登录服务器实现免密登录实战

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

Eth-Trunk 配置实例学习记录

PPP configuration instance learning record

4D天线阵列布局设计

Single arm routing configuration instance learning record

OSPF multi area configuration instance learning record

OSPF实验
随机推荐
ACL configuration instance learning record
FTP 配置实例学习记录
RK3588编译问题集
Solution rapide: xshell ne peut pas glisser dans un dossier ou un paquet
linx的链接、一级目录、重定向、cp与mv
FTP configuration instance learning record
Rhcsa -- file content browsing, cut, uniq, sort,.Tr command use
HCIA----07 ACL-Net
HCIA----06 OSPF
DHCP 配置实例学习记录
User and group management, file permissions
OSPF comprehensive experiment in hcip-mgre environment
C#输入一个字母,判断其大小写
0 shortest path problem leetcode743. Network delay time
Tar, SFTP, fin, history commands, variables, aliases
2020-09-22
秘钥远程登录服务器实现免密登录实战
Matplotlib-实现常见概率分布
HCIA----06 OSPF
ACL 配置实例学习记录