python经常用的语法

NumPy库

random.rand(4,4)

array([[ 0.50644331, 0.44375774, 0.79081 , 0.73889543],
[ 0.69320171, 0.64640474, 0.96746222, 0.99856647],
[ 0.26621224, 0.42479067, 0.65365039, 0.23237977],
[ 0.81672981, 0.53695627, 0.36692742, 0.9787382 ]])

mat(random.rand(4,4))

matrix([[ 0.91275385, 0.54632161, 0.25685307, 0.62581389],
[ 0.62642073, 0.31651896, 0.75398169, 0.17982347],
[ 0.72390911, 0.16819123, 0.18983078, 0.59421625],
[ 0.80979891, 0.17644632, 0.81972653, 0.20486715]])

Mat.I矩阵求逆
eye(4)
import matplotlib.pyplot as plt
plt.title("hw1,")
plt.xlim(xmax=100,xmin=0)
plt.ylim(ymax=120,ymin=0)
plt.xlabel("x")
plt.ylabel("y")
plt.plot(x,y,'ro',t,t+1,'ro')
plt.show()

计算相关系数

x=100*random.rand(50)
y=x+1
s1=Series(x)
s2=Series(y)
cor=s1.corr(s2)#计算相关系数

1.split()方法
a = ‘www.baidu.com’
print(a.split(‘.’))

result [‘www’, ‘baidu’, ‘com’]

2.repalce()方法
a = ‘There is apples’
b = a.replace(‘is’,’are’)
print(b)

result There are apples

3.strip()方法
a = ’ python is cool ’
print(a.strip())

result python is cool

strip()方法返回去除两侧(不包括内部)空格的字符串,也可以指定需要去除的字符,将他们列为参数中即可。
4.format()方法
最后,再讲解下好用的字符串格式化符,首先看下代码。
a = ‘{} is my love’.format(‘Python’)
print(a)

result Python is my love

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值