numpy入门——数组切片
来源:互联网 发布:闲鱼怎么换淘宝账号 编辑:程序博客网 时间:2024/06/06 04:40
数组切片
- 选取第二行第一列的数字
# 导入numpy包 以np的形式import numpy as np# 使用arange的方式创建一个二维数组a = np.arange(1,13).reshape((3,4))print(a)# 选取第二行第一列的数字print(a[2,1])
array([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12]])10
- 选取第二行的数据
print(a[2,:])
array([ 9, 10, 11, 12])
选取第二行与第二三列的数字
print(a[2,2:4])
array([11, 12])
-迭代遍历每一行的数
for row in a: print(row)
[1 2 3 4][5 6 7 8][ 9 10 11 12]
- 迭代遍历每一列数据
for column in a.T: print(column)
[1 5 9][ 2 6 10][ 3 7 11][ 4 8 12]
- 迭代遍历数组的每一项
for item in a.flat: print(item)
123456789101112
- 将数组组合成一维数组
print(a.flatten())
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
阅读全文
1 0
- numpy入门——数组切片
- numpy中的数组切片
- numpy数组切片
- Numpy ndarray数组切片
- numpy数组切片操作
- numpy数组切片与索引
- numpy入门——创建二维数组
- numpy入门——创建随机数组
- numpy入门——数组操作
- numpy入门——数组属性操作
- numpy入门——数组组合
- python numpy多维数组切片问题
- numpy中数组元素的切片复制
- NumPy数组基本的索引和切片
- numpy数组切片索引的详细讲解
- numpy多维数组的切片操作
- numpy入门——创建一维数组
- numpy入门——创建数组的其他方式
- STM32使用16M外部晶振时串口乱码
- 数组元素连接成字符串
- Vue v-for 的反面教材。
- 23 Three.js的光源种类
- (六)播放暂停、下一曲、上一曲功能实现
- numpy入门——数组切片
- Java面向对向编程之多态(polymorphism)
- linux VM与容器的网络IO性能测试
- 阻止用户复制、粘贴文本
- Python中的 __name__
- Unity 物理系统--物理材质
- 图像滤镜艺术---最新美颜算法研究
- Spring TestContext Framework对JUnit4和TestNG的集成支持详解
- es-重要参数