axis

numpy - 添加操作大全

醉酒当歌 提交于 2019-11-28 00:10:05
合并 hstack(tup) :按行合并  【前面有个 h,可以理解为 行,这样方便记忆】 vstack(tup) :按列合并 参数虽然是 tuple,但是 list 也行,可以合并2个或者多个数组。 a=np.floor(10*np.random.rand(2,2)) b=np.floor(10*np.random.rand(2,2)) ### hstack()在行上合并 np.hstack((a,b)) # array([[ 8., 5., 1., 9.], # [ 1., 6., 8., 5.]]) #### vstack()在列上合并 np.vstack((a,b)) # array([[ 8., 5.], # [ 1., 6.], # [ 1., 9.], # [ 8., 5.]]) print np.vstack([a,b,b]) # list 参数 # [[ 1. 4.] a # [ 9. 5.] # [ 7. 6.] b # [ 2. 9.] # [ 7. 6.] b # [ 2. 9.]] 追加 append(arr, values, axis=None) :可以追加数组,也可以追加数字,追加数组相当于合并。 arr 分为一维和二维 一维:只有一个方向,故只能在一个维度上追加 二维:两个二维数组,拼接方向上 shape 必须一致 二者皆可追加数字

关于axis=0,axis=1理解

喜欢而已 提交于 2019-11-28 00:04:48
根据官方的说法,1表示横轴,方向从左到右;0表示纵轴,方向从上到下。当axis=1时,数组的变化是横向的,而体现出来的是列的增加或者减少。 axis=0代表跨行(down),而axis=1代表跨列(across)。 轴用来为超过一维的数组定义的属性,二维数据拥有两个轴:第0轴沿着行的垂直往下,第1轴沿着列的方向水平延伸。 换句话说: 使用0值表示沿着每一列或行标签/索引值向下执行方法 使用1值表示沿着每一行或者列标签横向执行对应的方法 import numpy as np #创建二维数组 arr2d = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]]) #沿第0轴方向最大值 print(arr2d.max(0)) import pandas as pd #创建二维数组 df = pd.DataFrame([[1,2,3,4],[5,6,7,8],[9,10,11,12]],columns=["col1", "col2", "col3","col4"]) df1=df.drop("col4", axis=1) print(df1) 来源: https://www.cnblogs.com/chen8023miss/p/11381781.html

深度学习面试题20:GoogLeNet(Inception V1)

随声附和 提交于 2019-11-27 23:58:36
目录    简介    网络结构    对应代码    网络说明    参考资料 简介 2014年,GoogLeNet和VGG是当年ImageNet挑战赛(ILSVRC14)的双雄,GoogLeNet获得了第一名、VGG获得了第二名,这两类模型结构的共同特点是层次更深了。VGG继承了LeNet以及AlexNet的一些框架结构,而GoogLeNet则做了更加大胆的网络结构尝试,虽然深度只有22层,但大小却比AlexNet和VGG小很多,GoogleNet参数为500万个,AlexNet参数个数是GoogleNet的12倍,VGGNet参数又是AlexNet的3倍,因此在内存或计算资源有限时,GoogleNet是比较好的选择;从模型结果来看,GoogLeNet的性能却更加优越。 GoogLeNet是谷歌(Google)研究出来的深度网络结构,为什么不叫“GoogleNet”,而叫“GoogLeNet”,是为了向“LeNet”致敬,因此取名为“GoogLeNet” GoogLeNet团队要打造一个Inception模块(名字源于盗梦空间),让深度网络的表现更好。 返回目录 网络结构 PS:Slim是2016年开发出来的,即使在InceptionV1中,他也没有使用论文里说的5*5的卷积核,而是用的3*3的卷积核。 返回目录 对应代码 这里采用的官网的代码tensorflow/models

Kaggle比赛(一)Titanic: Machine Learning from Disaster

天大地大妈咪最大 提交于 2019-11-27 22:11:58
泰坦尼克号幸存预测 是本小白接触的第一个Kaggle入门比赛,主要参考了以下两篇教程: https://www.cnblogs.com/star-zhao/p/9801196.html https://zhuanlan.zhihu.com/p/30538352 本模型在Leaderboard上的最高得分为0.79904,排名前13%。 由于这个比赛做得比较早了,当时很多分析的细节都忘了,而且由于是第一次做,整体还是非常简陋的。今天心血来潮,就当做个简单的记录(流水账)。 导入相关包: import numpy as np import pandas as pd import matplotlib.pyplot as plt import re from sklearn.model_selection import GridSearchCV from sklearn.linear_model import LinearRegression from sklearn.ensemble import GradientBoostingRegressor from sklearn.ensemble import ExtraTreesClassifier, RandomForestClassifier, GradientBoostingClassifier, VotingClassifier

numpy 介绍和基础使用详解

风流意气都作罢 提交于 2019-11-27 21:54:51
/*--> */ /*--> */ NUMPY INTRODUCTION NUMPY 提供了一个在Python中做科学计算的基础库,重在数值计算,主要用于处理多维数组,用于储存和处理大型矩阵,本身是由C语言开发,比python自身的列表结构要高效的多。 高性能科学计算和数据分析的基础包,总结: /*--> */ /*--> */ • NUMPY 是一个 Python 科学计算基础库,提供了多维向量 • NUMPY 提供了用于数组快速操作的方法,数学,逻辑,排序,选择,线性代数,统计等 • NUMPY 采用预编译的 C 代码完成,效率更高 安装: pip install numpy 使用: import numpy as np 行业惯例将np作为numpy,将pd作为pandas。下文所有np均指的是numpy 认识轴: 轴【axis】: 既然是多维数组,先理清一下轴,类似于我们学习的X、Y、Z 二维数组的轴: 图一 三维数组的轴: 图二 使用NUMPY创建数组: 例:创建一个图一的数组 1 2 3 4 5 6 方法1: np.array([]) a=np.array([[1,2,3],[4,5,6]]) b=np.array([range(1,4),range(4,7)]) c=np.array([[i for i in range(1,4)],[i for i in range

第一阶段:Python开发基础 day18 模块的使用(三)

假装没事ソ 提交于 2019-11-27 21:34:52
目录 上节课内容回顾 一、numpy模块 一、numpy简介 二、为什么用numpy 三、创建numpy数组 五、获取numpy数组的行列数 六、切割numpy数组 七、numpy数组元素替换 八、numpy数组的合并 九、通过函数创建numpy数组 十、numpy数组运算 十一、numpy数组运算函数 十二、numpy数组矩阵化 十三、numpy数组数学和统计方法 十四、numpy.random生成随机数 二、pandas模块 一、Series数据结构 三、DataFrame属性 四、DataFrame取值 五、DataFrame值替换 六、读取CSV文件 七、处理丢失数据 九、导入导出数据 十、pandas读取json文件 10.1 orient参数的五种形式 十一、pandas读取sql语句 三、matplotlib模块 一、条形图 二、直方图 三、折线图 四、散点图+直线图 五、饼图 六、箱型图 七、plot函数参数 八、图像标注参数 今日总结 上节课内容回顾 包 一个模块aaa.py中方法太多了, 所以分成多个文件m1.py, m2.py, 把m1.py和m2.py放到名字为aaa的包(含有init文件的文件夹叫包)里 导入aaa包就是导入init, 所以往init里面加入一个f1() import aaa aaa.f1() import aaa aaa.f1() ##

Suppress ticks in plot in r

陌路散爱 提交于 2019-11-27 21:34:50
问题 I want to remove labels and axis from X axis, however adding new ticks. plot(1:10, ylab = "") at1 <- seq(1, 10, 0.1) axis(side = 1, at = at1, labels = FALSE) I could not get rid of y labels. 回答1: see ?par You need the xaxt argument plot(1:10, ylab = "", xaxt='n') 回答2: I am not certain what you want, but this removes the x label and uses the tick marks you are generating with at1: plot(1:10, ylab = "", xlab="") at1 <- seq(1, 10, 0.1) axis(side =1, at1, labels = F) I took the suggestion by GSee

Relative positioning of geom_text in ggplot2?

て烟熏妆下的殇ゞ 提交于 2019-11-27 21:33:27
I am using geom_text to annotate plots in gglot2 and I want use relative positioning rather than absolute. That is, I want a position of (0.5, 0.5) to be dead center regardless of the x and y axis limits. Is that possible? Alternatively I could of course transform a relative position to an absolute one if I had the x and y limits. Is it possible to extract those from a plot? If you know the range of the data in your plot, you can calculate the "true" x and y limits using the fact that ggplot using an additive expansion factor of 0.05 by default, so that the extents of the graph extend just

day18学习整理-Python模块

孤街醉人 提交于 2019-11-27 21:25:32
目录 2019/08/16 学习整理 函数进阶(模块) numpy模块 创建矩阵(掌握) 获取矩阵的行列数(掌握) 切割矩阵(掌握) 矩阵元素替换(掌握) 矩阵的合并(熟悉) 通过函数创建矩阵(掌握) arange linspace/logspace zeros/ones/eye/empty fromstring/fromfunction(了解) 矩阵的运算(掌握) 普通矩阵运算 常用矩阵运算函数(了解) 矩阵的点乘(掌握) 矩阵的转置(掌握) 矩阵的逆(掌握) 矩阵其他操作(熟悉) 最大最小值 平均值 方差 标准差 中位数 矩阵求和 累加和 numpy.random生成随机数(熟悉) pandas模块 Series(熟悉) DataFrame(掌握) DataFrame属性(掌握) DataFrame取值(掌握) loc/iloc 使用逻辑判断取值 DataFrame值替换(掌握) 读取CSV文件(掌握) 处理丢失数据(掌握) 导入导出数据(掌握) 合并数据(掌握) 读取sql语句(熟悉) matplotlib模块 条形图(掌握) 直方图(掌握) 折线图(掌握) 散点图+直线图(掌握) 2019/08/16 学习整理 函数进阶(模块) 建议学习的时候去看官方文档学习 numpy模块 numpy官方文档: https://docs.scipy.org/doc/numpy

Axes class - set explicitly size (width/height) of axes in given units

China☆狼群 提交于 2019-11-27 19:11:48
I want to to create a figure using matplotlib where I can explicitly specify the size of the axes, i.e. I want to set the width and height of the axes bbox. I have looked around all over and I cannot find a solution for this. What I typically find is how to adjust the size of the complete Figure (including ticks and labels), for example using fig, ax = plt.subplots(figsize=(w, h)) This is very important for me as I want to have a 1:1 scale of the axes, i.e. 1 unit in paper is equal to 1 unit in reality. For example, if xrange is 0 to 10 with major tick = 1 and x axis is 10cm, then 1 major tick