Python实用技巧_1

1.np.arange()
函数返回一个有终点和起点的固定步长的排列,如[1,2,3,4,5],起点是1,终点是5,步长为17.time = np.linspace(0, 10, 2000)
0-10生成2000个数	
2.np.where(condition, x, y)
满足条件(condition),输出x,不满足输出y。
3.np.lexsort
lexsort支持对数组按指定行或列的顺序排序
以免浅拷贝:
>>> lists = [[] for i in range(3)]
>>> lists[0].append(3)
>>> lists[1].append(5)
>>> lists[2].append(7)
>>> lists
[[3], [5], [7]]
二维数组创建方式为:
myList = [([0] * 3) for i in range(4)]
5.np.full(shape, fill_value)
可以生成一个元素为fill_value,形状为shape的array
6.计时器
import time

time_start=time.time()

for i in range(10):
    print(i)
time_end=time.time()
print('totally cost',time_end-time_start)
对二维数组
—— np.where()[0] 表示行的索引;
—— np.where()[1] 则表示列的索引
7. np.argsort 返回从小到大顺序的索引列表
8. 主函数的设置
def main():
    ph = loadmat('detrend_ph')
    h2p = loadmat('h2p_se')
    dem_error, max_corr, ph_correct = ica_dem_error_single_2019(ph, h2p)
    
if __name__=='__main__':
    main()
9.存储.mat文件

import scipy.io as scio
from scipy.io import savemat

aL = detrend_ph.conj().T
bB = h2p_se
scio.savemat('aL.mat', {'aL':aL})
scio.savemat('bB.mat', {'bB':bB})

加载.mat文件
from scipy.io import loadmat
h2p = loadmat("h2p_se.mat")["h2p_se"]
ph = loadmat("detrend_ph.mat")["detrend_ph"]
Ndim,NPS = np.shape(ph)
10.数组行向量转换成列向量

a = np.array([x for x in range (5)])
print(a.shape)
print(a)
a = a[:,np.newaxis]
print(a)
13. str.lower()
Python lower() 方法转换字符串中所有大写字符为小写。
6.del a 删除变量a
2. 注意:一维数组转置仍为一维数组。可用[:,np.newaxis]转为列向量  
3. 可遍历的数据类型:列表,元组,字符串
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十子木

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值