bumpy matlab 索引,numpy,scipy,matlabplotlib,pandas学习笔记

直接赋值是引用,改变 新变量值会改变原变量值。

使用c = a.view()是建立了一个a的观测值变量,改变c也会改变a。

要完全赋值使用深拷贝d = a.copy()

numpy中可以直接用多维索引来建立一个多维array。但注意,不能将多个array作为索引,此时可以用tuple(多个array)将多个array转换成一个tuple

r_连接二维行 c_连接二维列。

a = np.r_[3,[0]5,-1:1:10j]*

其中10j的意思是铸造10个分割点

mgrid铸造标准网格,类似matlab的meshgrid;ogrid返回的是多个一维的网格向量。

vectorize(函子)传入函子,返回一个向量化的函数

select函数的 意思通过下面这个例子说明:

x = np.r_[-2:3]

x

array([-2, -1, 0, 1, 2])

np.select([x > 3, x >= 0], [0, x+2],999)

array([999, 999, 2, 3, 4])

也就是说x来进行判断,满足第一个条件就被0替换,满足第二个条件被x+2替换,如果都不满足就被999替换。

而where函数有两种用法:

np.where([[True, False], [True, True]],

... [[1, 2], [3, 4]],

... [[9, 8], [7, 6]])

array([[1, 8],

[3, 4]])

满足条件取第一个,不满足取第二个

第二种用法:只有一个输入参数,那么就返回True

注意Matplotlib所用的都是()而不是[].

可以使用latex格式,但要在

label=r"

math?formula=y%20%3D%20%5Calpha%5E3"

注意要加r来区分和python变量str区别。

注意plot和subplot的属性名:

属性名

简写

功能

备注

label="curve1"

线标签

最后要加ax.legend();

苹果

$1

6

6

草莓

$1

7

6

a.

ax.plot(x, x2, label="curve1")

ax.plot(x, x3, label="curve2")

label="curve1"线标签

ax.legend(loc=0) # let matplotlib decide the optimal location

ax.legend(loc=1) # upper right corner

ax.legend(loc=2) # upper left corner

ax.legend(loc=3) # lower left corner

ax.legend(loc=4) # lower right corner

b.

ax.plot(x, x+13, color="purple", lw=1, ls='-', marker='o', markersize=2)

ax.plot(x, x+14, color="purple", lw=1, ls='-', marker='o', markersize=4)

ax.plot(x, x+15, color="purple", lw=1, ls='-', marker='o', markersize=8, markerfacecolor="red")

ax.plot(x, x+16, color="purple", lw=1, ls='-', marker='s', markersize=8,

markerfacecolor="yellow", markeredgewidth=2, markeredgecolor="blue");

lw是linewidth,ls是linestyle线形状,marker是点型

c. 决定坐标范围

fig, axes = plt.subplots(1, 3, figsize=(12, 4))

axes[0].plot(x, x2, x, x3)

axes[0].set_title("default axes ranges")

axes[1].plot(x, x2, x, x3)

axes[1].axis('tight') #(自决定)

axes[1].set_title("tight axes")

axes[2].plot(x, x2, x, x3)

axes[2].set_ylim([0, 60])

axes[2].set_xlim([2, 5])

axes[2].set_title("custom axes range");

d. 坐标指数

fig, axes = plt.subplots(1, 2, figsize=(10,4))

axes[0].plot(x, x**2, x, np.exp(x))

axes[0].set_title("Normal scale")

axes[1].plot(x, x**2, x, np.exp(x))

axes[1].set_yscale("log")

axes[1].set_title("Logarithmic scale (y)");

改变图像风格:

plt.style.use('ggplot')

可以先使用

print(plt.style.available)

查看图像风格

sns.lmplot(x='total_bill', y='tip', data=tips, col='sex')

col,row将不同的分类点画在不同画布上;hue='sex'将分类点画在同一画布上,但标出不同颜色。

6.二变量画图法:

sns.jointplot(x='hp',y='mpg',data=auto,kind='resid')

kind='scatter' uses a scatter plot of the data points

kind='reg' uses a regression plot (default order 1)

kind='resid' uses a residual plot

kind='kde' uses a kernel density estimate of the joint distribution

kind='hex' uses a hexbin plot of the joint distribution

多变量画图:

注意,传入的都要是dataframe

sns.pairplot(data)非常简单

sns.heatmap(cov_matrix)相关性的图

注意深拷贝berri_bikes = bikes[['Berri 1']].copy()一定要用copy,注意bikes后有两个中括号

rows_with_dashes = requests['Incident Zip'].str.contains('-').fillna(False)

fillna的含义是充填缺失值

daily_temp_2011 = daily_mean_2011['dry_bulb_faren'].values

.values让一个series(pandas)转换成了array(numpy)

pandas内容太多了,建议还是直接看官方cookbook

一列写入的时候,要用双[],否则会当做series没有列名。列选择都要加双[],即

data[['rnd_1', 'rnd_3']]

也就是说从dataframe里面选出列名的那些列作为dataframe要加双括号

sklearn

tranform()的作用是通过找中心和缩放等实现标准化

fit_transform()的作用就是先将数据拟合模型,然后转化它将其转化为标准形式

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值