当前位置:网站首页>numpy.newaxis
numpy.newaxis
2022-07-26 19:12:00 【Wanderer001】
>> type(np.newaxis)
NoneType
>> np.newaxis == None
Truenp.newaxis 在使用和功能上等价于 None,其实就是 None 的一个别名。
1. np.newaxis 的实用
>> x = np.arange(3)
>> x
array([0, 1, 2])
>> x.shape
(3,)
>> x[:, np.newaxis]
array([[0],
[1],
[2]])
>> x[:, None]
array([[0],
[1],
[2]])
>> x[:, np.newaxis].shape
(3, 1)
2. 索引多维数组的某一列时返回的是一个行向量
>>> X = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
>>> X[:, 1]
array([2, 6, 10]) % 这里是一个行
>>> X[:, 1].shape % X[:, 1] 的用法完全等同于一个行,而不是一个列,
(3, )如果我索引多维数组的某一列时,返回的仍然是列的结构,一种正确的索引方式是:
>>>X[:, 1][:, np.newaxis]
array([[2],
[6],
[10]])如果想实现第二列和第四列的拼接(层叠):
>>>X_sub = np.hstack([X[:, 1][:, np.newaxis], X[:, 3][:, np.newaxis]])
% hstack:horizontal stack,水平方向上的层叠
>>>X_sub
array([[2, 4]
[6, 8]
[10, 12]])当然更为简单的方式还是使用切片:
>> X[:, [1, 3]]
array([[ 2, 4],
[ 6, 8],
[10, 12]])边栏推荐
- 计算机专业面试题目总结,总导航
- JWT 实现登录认证 + Token 自动续期方案,这才是正确的使用姿势!
- 【机器学习】变量间的相关性分析
- Principle analysis and source code interpretation of service discovery
- Leetcode daily practice - 27. Remove elements
- 金仓数据库 KingbaseES SQL 语言参考手册 (19. SQL语句: DROP TABLE 到 LOAD)
- 靠元宇宙和NFT,天下秀疯狂“割韭菜”?
- Where can I find the files downloaded from iPad
- Method of replacing Chinese characters with PHP
- 金仓数据库 KingbaseES SQL 语言参考手册 (21. KES正则表达式支持)
猜你喜欢
![[PHP] save session data to redis](/img/29/70a9f330b9f912ccbd57e865372439.png)
[PHP] save session data to redis

使用三重损失和孪生神经网络训练大型类目的嵌入表示

企业内部信息碎片化该怎么办?不妨试试这样做

DevOps 实践多年,最痛的居然是?

KVM virtualization

Redis6

These 22 drawing (visualization) methods are very important and worth collecting!

一年卖7亿,德州扒鸡赶考IPO

几张图帮你捋清“中国金融机构体系”

Intensive reading of the paper: yolov2 - yolo9000: better, faster, stronger
随机推荐
[internship experience] exception handling and URL result response data processing
金仓数据库 KingbaseES SQL 语言参考手册 (13. SQL语句:ALTER SYNONYM 到 COMMENT)
一文看懂中国的金融体系
Kingbases SQL language reference manual of Jincang database (13. SQL statement: alter synonym to comment)
Latte dht-phev products are very popular. Will the sales volume make Li Ruifeng figure it out?
Kingbasees SQL language reference manual of Jincang database (12. SQL statement: alter language to alter subscription)
Linux regularly backs up the database and deletes the data n days ago
数据库设计三大范式
DevSecOps,让速度和安全兼顾
千亿酸奶赛道,乳企巨头和新品牌打响拉锯战
These 22 drawing (visualization) methods are very important and worth collecting!
LeetCode每日一练 —— 189. 轮转数组
计算机网络常见面试题目总结,含答案
京东荣获中国智能科学技术最高奖!盘点京东体系智能技术
Design of intelligent weighing system based on Huawei cloud IOT (STM32) [i]
Uiobject2 of uiautomator2 common classes
金仓数据库 KingbaseES SQL 语言参考手册 (21. KES正则表达式支持)
go+mysql+redis+vue3简单聊室,第5弹:使用消息队列和定时任务同步消息到mysql
【实习经验】异常处理与访问url结果响应数据处理
TableWidget