当前位置:网站首页>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]])边栏推荐
- 计算机专业面试题目总结,总导航
- Method of replacing Chinese characters with PHP
- 原 iOS面试题收集
- 徽商期货开户安全吗?请问徽商期货开户应该注意什么呢?
- LeetCode每日一练 —— 26. 删除有序数组中的重复项
- 【PHP】将 SESSION 数据保存到 Redis
- 6种方法帮你搞定SimpleDateFormat类不是线程安全的问题
- Kingbases SQL language reference manual of Jincang database (14. SQL statement: commit to create language)
- 客户案例|生学教育依托观测云打造可观测智慧教育新生态
- Leetcode daily practice - 26. Delete duplicates in an ordered array
猜你喜欢

中天钢铁在 GPS、 AIS 调度中使用 TDengine

【OBS】解决OBS推两个rtmp流 + 带时间戳问题

一文看懂中国的金融体系

Latte dht-phev products are very popular. Will the sales volume make Li Ruifeng figure it out?

Codeforces Round #810 (Div. 2)(A~C)

Overview of canvas

靠元宇宙和NFT,天下秀疯狂“割韭菜”?

Codeforces Round #810 (Div. 2)(A~C)

plsql包

Ijcai2022 meeting! Brescia et al. Tutorial of evidential reasoning and learning, describing its latest progress, with 96 slides attached
随机推荐
【PHP】常用的header头部定义
Analysis of interface testing
【JVM 系列】JVM 调优
Detailed explanation of call function in solidity
Excel-VBA 快速上手(十一、字符串常用操作)
计算机专业面试题目总结,总导航
【实习经验】异常处理与访问url结果响应数据处理
Zhongtian steel uses tdengine in GPS and AIS scheduling
【ffmpeg】给视频文件添加时间戳 汇总
十大排序详解
Familiarize you with the "phone book" of cloud network: DNS
计算机组成原理常见面试题目总结,含答案
6种方法帮你搞定SimpleDateFormat类不是线程安全的问题
[PHP] common header definitions
[internship experience] exception handling and URL result response data processing
Bug feedback: synchronization failed
There are six ways to help you deal with the simpledateformat class, which is not a thread safety problem
Codeforces Round #810 (Div. 2)(A~C)
数据库笔记(来自老社)
【shell】转载:批量替换 find awk sed xargs