Numpy array 合并
1、np.vstack() :垂直合并
>>> import numpy as np
>>> A = np.array([1,1,1])
>>> B = np.array([2,2,2])
>>> print(np.vstack((A,B))) # vertical stack,属于一种上下合并,即对括号中的两个整体进行对应操作
[[1 1 1]
[2 2 2]] >>> C = np.vstack((A,B))
>>> print(A.shape,C.shape)
(3,) (2, 3)
2、np.hstack():水平合并
>>> D = np.hstack((A,B)) # horizontal stack,即左右合并
>>> print(D)
[1 1 1 2 2 2]
>>> print(A.shape,D.shape)
(3,) (6,)
3、np.newaxis():转置
>>> print(A[np.newaxis,:])
[[1 1 1]]
>>> print(A[np.newaxis,:].shape)
(1, 3)
>>> print(A[:,np.newaxis])
[[1]
[1]
[1]]
>>> print(A[:,np.newaxis].shape)
(3, 1) >>> A = np.array([1,1,1])[:,np.newaxis]
>>> B = np.array([2,2,2])[:,np.newaxis]
>>> C = np.vstack((A,B)) # vertical stack
>>> D = np.hstack((A,B)) # horizontal stack
>>> print(D)
[[1 2]
[1 2]
[1 2]]
>>> print(A.shape,D.shape)
(3, 1) (3, 2)
4、np.concatenate():针对多个矩阵或序列的合并操作
#axis参数很好的控制了矩阵的纵向或是横向打印,相比较vstack和hstack函数显得更加
>>> C = np.concatenate((A,B,B,A),axis=0)
>>> print(C)
[[1]
[1]
[1]
[2]
[2]
[2]
[2]
[2]
[2]
[1]
[1]
[1]] >>> D = np.concatenate((A,B,B,A),axis=1)
>>> print(D)
[[1 2 2 1]
[1 2 2 1]
[1 2 2 1]]
Numpy array 合并的更多相关文章
- numpy.array 合并和分割
# 导包 import numpy as np numpy.array 的合并 .concatenate() 一维数组 x = np.array([1, 2, 3]) # array([1, 2, 3 ...
- python numpy array 的一些问题
1 将list转换成array 如果list的嵌套数组是不规整的,如 a = [[1,2], [3,4,5]] 则a = numpy.array(a)之后 a的type是ndarray,但是a中得元素 ...
- Python Numpy Array
Numpy 是Python中数据科学中的核心组件,它给我们提供了多维度高性能数组对象. Arrays Numpy.array dtype 变量 dtype变量,用来存放数据类型, 创建数组时可以同 ...
- numpy.array
关于python中的二维数组,主要有list和numpy.array两种. 好吧,其实还有matrices,但它必须是2维的,而numpy arrays (ndarrays) 可以是多维的. 我们主要 ...
- gensim与numpy array 互转
目的 将gensim输出的格式转化为numpy array格式,支持作为scikit-learn,tensorflow的输入 实施 使用nltk库的停用词和网上收集的资料整合成一份新的停用词表,用来过 ...
- 找出numpy array数组的最值及其索引
在list列表中,max(list)可以得到list的最大值,list.index(max(list))可以得到最大值对应的索引 但在numpy中的array没有index方法,取而代之的是where ...
- 「Python」Convert map object to numpy array in python 3
转自Stackoverflow.备忘用. Question In Python 2 I could do the following: import numpy as np f = lambda x: ...
- python numpy array 与matrix 乘方
python numpy array 与matrix 乘方 编程语言 waitig 1年前 (2017-04-18) 1272℃ 百度已收录 0评论 数组array 的乘方(**为乘方运算符)是每个元 ...
- numpy.array 基本操作
import numpy as np np.random.seed(0) x = np.arange(10) x """ array([0, 1, 2, 3, 4, 5, ...
随机推荐
- unity3d assetbundle打包策略
由于assetbundle打包存在依赖的问题,所有资源要进行合理的分包 零.代码 代码都放在本地,包括NGUI等插件的代码.shader代码(内置的shader无需打包,而自定义的shader还是需要 ...
- 吴裕雄 python 机器学习-NBYS(1)
import numpy as np def loadDataSet(): postingList=[['my', 'dog', 'has', 'flea', 'problems', 'help', ...
- Python之路 - Socketserver实现多并发
Python之路 - Socketserver实现多并发 阅读指引
- ERROR Couldn't find hvm kernel for Ubuntu tree.
安装python-virtinst git clone https://github.com/palli/python-virtinst.gitcd python-virtinstpython set ...
- JVM 图解--1.6,1.7,1.8
- burpsuite的使用(一)
安装证书: 打开burpsuite,设置好代理.端口8080,但是打开https的网站却因为证书问题无法访问. 这需要我们为浏览器手动安装CA证书, 安装CA证书有两种方式: 1. 在burpsuit ...
- spark快速开发之scala基础之3类,对象,特征
类 scala的类定义非常灵活 class test4 class test2{} class test3(x:Int) 定义一个带构造函数的类 class Point (x : Int,y : In ...
- android 区分wifi是5G还是2.4G(转)
http://bbs.csdn.net/topics/391033966?page=1 我一开始看这帖子,找不到答案,为了后来的人,我来回复吧.WifiManager wifiManager = (W ...
- SpringBoot配置logback
1.在SpringBoot中已经集成了logback.在pom.xml中加入以下spring-boot-starter依赖,使用默认版本即可: <dependency> <group ...
- HDFS 总结
HDFS是一个分布式文件存储系统 Client 提交读写请求(拆分blocksize) NameNode 全局把控(知道blocksize的地址) dataNode 存储数据(将数据存储进去,且以P ...