python 学习中的小技术(与matlab不同的地方)

3*3的零矩阵:returnMat = zeros((3,3))

line.strip():截取掉行的回车字符

缩进用空格,不要用tab键,避免编译通不过


画带颜色的散点图:

import matplotlib

import matplotlib.pyplot as plt


fig = plt.figure()

ax = fig.add_subplot(111)

ax.scatter(datingDataMat[:,0],datingDataMat[:,1],15.0*array(datingLabels),15.0*array(datingLabels))

plt.show()

#datingLabels表示样本标签


#归一化特征值方法

newValue = (oldValue - min)/(max - min)


#获得相同大小的零矩阵

a=zeros(shape(b))


#矩阵拼接,按2行3列的方式拼接a矩阵

tile(a,(2,3))


#获得目录下的文件内容

import os 

os.listdir(filename)


#split字符串分割用"."

fileStr = fileNameStr.split('.')[0]


#获取dataSet中第i个元素形成集合

set([example[i] for example in dataSet])


#list转化为mat,并转置

mat(classLabels).T


#wind提取到的日期转化为‘20100102’格式

today_str = str(s_time.year) + (lambda x : str(x) if x > 9 else '0' + str(x))(s_time.month) + (lambda x : str(x) if x > 9 else '0' + str(x))(s_time.day)


  1. #取差集
  2. list(set(b).difference(set(a))) # b中有而a中没有的




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值