当前位置 博文首页 > Weiyaner的博客:Python便捷使用(时间戳、GPU)
本文开设目的是为了记录在学习使用python的过程中常见的使用操作,等需要的时候便于查看,与其说是为了分享,不如说是为了自查,因为本人记性实在不太好,经常使用了忘,忘了又百度,百度了又忘记了…
import time
start =time.clock()
#中间写上代码块
end = time.clock()
print('Running time: %s Seconds'%(end-start))
2.1 通过tensorflow
import tensorflow as tf
tf.device('/gpu:1')
2.2 通过os启动
import os
os.environ('CUDA_VISIBLE_DEVICES') = '1'
os.environ('CUDA_VISIBLE_DEVICES') = '1,2'
3.1 逆序循环
for i in range(num,-1,-1):
4.1 一维列表转二维
res = np.reshape(res, (int(len(res)/3), 3)) # 一维列表转二维数组
res = res.tolist() # 数组转列表
4.2 不改变顺序二位列表去重
dic = list(set([tuple(t) for t in res])) # 此时已经乱序
dic = [list(v) for v in dic] # 将元组转成list
dic.sort(key=res.index) # 按照res出现的顺序重新排列
cs