博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
numpy的基本用法(四)——numpy array合并
阅读量:3977 次
发布时间:2019-05-24

本文共 1006 字,大约阅读时间需要 3 分钟。

文章作者:Tyan

博客:  |   | 

本文主要是关于numpy的一些基本运算的用法。

#!/usr/bin/env python# _*_ coding: utf-8 _*_import numpy as np# Test 1A = np.array([1, 1, 1])B = np.array([2, 2, 2])# 合并array, 竖直方向C = np.vstack((A, B))print A.shapeprint C.shapeprint C# 合并array, 水平方向D = np.hstack((A, B))print A.shapeprint D.shapeprint D# Test 1 result(3,)(2, 3)[[1 1 1] [2 2 2]](3,)(6,)[1 1 1 2 2 2]# Test 2A = np.array([1, 1, 1])# 添加维度# 列方向上添加维度B = A[:, np.newaxis]print Aprint Bprint A.shapeprint B.shape# 行方向上添加维度C = A[np.newaxis, :]print Aprint Cprint A.shapeprint C.shape# Test 2 result[1 1 1][[1] [1] [1]](3,)(3, 1)[1 1 1][[1 1 1]](3,)(1, 3)# Test 3A = np.array([1, 1, 1])B = np.array([2, 2, 2])# A, B列方向添加维度A = A[:, np.newaxis]B = B[:, np.newaxis]# 合并多个array并指定合并的维度, 列方向上合并C = np.concatenate((A, B, B, A), axis = 0)# 合并多个array并指定合并的维度, 行方向上合并D = np.concatenate((A, B, B, A), axis = 1)print Aprint Bprint Cprint D# Test 3 result[[1] [1] [1]][[2] [2] [2]][[1] [1] [1] [2] [2] [2] [2] [2] [2] [1] [1] [1]][[1 2 2 1] [1 2 2 1] [1 2 2 1]]

参考资料

转载地址:http://lcwui.baihongyu.com/

你可能感兴趣的文章
netcat
查看>>
Linux下如何查看CPU信息, 包括位数和多核信息
查看>>
Linux命令行访问网页
查看>>
VMware网络连接 桥接、NAt、host-only模式
查看>>
VMware网络设置详解 打造超级虚拟网络
查看>>
关于MYSQL Error:ERROR 1005 (HY000) at line 3: Can't create table '.\xx.frm'错误
查看>>
linux命令行获取机器的物理地址并打印及Linux获取系统信息的常用命令
查看>>
解决在CentOS 5.5 yum源下载慢的办法即修改yum源
查看>>
PHP中exec、system等函数调用linux命令问题
查看>>
httpd.conf文件配置详解
查看>>
php shell_exec()与反撇号等价输出结果
查看>>
chmod 命令,主要是+s的选项
查看>>
linux 里命令ls -l 后,文件类型权限后面的数字什么意思
查看>>
Vmware无法登陆Web Interface的解决
查看>>
软件版本常识和软件版本号命名规则
查看>>
shell判断文件是否存在
查看>>
解决FCKeditor在线文本编辑器自动过滤HTML标签的方法
查看>>
Centos 时间同步
查看>>
linux中用shell获取昨天、明天或多天前的日期
查看>>
crontab命令详解
查看>>