![](https://img-blog.csdnimg.cn/20190918140145169.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
编程技巧
使用python,java,c等编程的小技巧.一句话:python,java,c的大杂烩
快去写论文
秋秋1216990865
展开
-
Linux中Adding visible gpu devices: 0 每次运行到这里卡很久
Adding visible gpu devices: 0 每次运行到这里卡很久我们参考win中的想法.参考1 :https://www.csdn.net/tags/MtTaMg1sODkzNjE2LWJsb2cO0O0O.html在linux中,export CUDA_CACHE_MAXSIZE=4294967296 ,没想到真的变快了.你可以通过如下命令测试是否有变快的感觉import tensorflow as tfa = tf.test.is_gpu_available()prin原创 2022-05-10 11:52:45 · 1125 阅读 · 0 评论 -
word2vec实现-只使用numpy
这是一个不使用api,只使用numpy的方法,当然反向传播得用pytorch.import numpy as npfrom collections import defaultdict class word2vec(): def __init__(self): self.n = settings['n'] self.lr = settings['learning_rate'] self.epochs = settings['epochs原创 2022-05-05 21:43:34 · 202 阅读 · 0 评论 -
python的实例和类.
import refrom shutil import moveimport numpy as npclass ap(): def ca1(self,a): a = a+1 return a def ca3(a): a = a+1 return a def ca2(self,x): #x = self.ca1(x)#调用实例的方法需要self x = ap.ca3(x) #调用类的方原创 2022-05-05 21:34:49 · 569 阅读 · 0 评论 -
python类中的函数调用,关于self
class ap(): def ca1(self,a): a = a+1 return a def ca3(a): a = a+1 return a def ca2(self,x): x = self.ca1(x)#调用实例的方法需要self #x = ap.ca3(x) #调用类的方法要这样调用. return xa = ap()b = a.ca2(3)#ca2带se原创 2022-04-16 19:08:48 · 1742 阅读 · 0 评论 -
文件路径的斜杠
以os.listdir为例子哈.import osa = os.listdir('..\APPS/')#显示文件夹,而且感觉左斜杠或者右斜杠没啥影响.print(a)#['.git', '.gitignore', 'APPS', 'eval', 'LICENSE', 'README.md', 'requirements.txt', 'train']原创 2021-12-15 11:20:23 · 1623 阅读 · 0 评论 -
如何查看自己的代理ip地址
使用python代码import requestsproxy = '127.0.0.1:10809' proxies = { 'http': 'http://' + proxy, 'https': 'https://' + proxy }try: response = requests.get('http://httpbin.org/get', proxies=proxies) print(response.text)except r原创 2021-12-15 09:46:07 · 6399 阅读 · 0 评论 -
优雅计算python程序的运行时间
当然是使用装饰器了装饰器装饰器是一个装饰函数的函数,能够在不改变函数源码和函数调用方式的情况下给函数增加新的功能。很多时候统计函数的耗时,可以使用装饰器实现。import timedef get_time(f): def inner(*arg,**kwarg): s_time = time.time() res = f(*arg,**kwarg) e_time = time.time() print('耗时:{}秒'.forma原创 2021-12-09 11:06:09 · 335 阅读 · 0 评论 -
python 装饰器
python 的装饰器举例说明def logging(level): def outwrapper(func): def wrapper(*args, **kwargs): print("[{0}]: enter {1}()".format(level, func.__name__)) return func(*args, **kwargs) return wrapper return outwrapper原创 2021-11-03 09:48:00 · 44 阅读 · 0 评论 -
解决treelib建立的二叉树的节点不按建立顺序排列
from treelib import Node, Treetree = Tree()tree.create_node('class_fun',1)tree.create_node('class',2,parent=1)tree.create_node('identifier',3,parent=1)tree.create_node('assign',4,parent=1)tree.create_node(':',5,parent=1)tree.show()tree.show(key=Fal原创 2021-10-14 17:01:59 · 291 阅读 · 0 评论 -
使用对象思维,结构体思维
def ast_clone(tree,text): def name(node): return node.__class__.__name__ from treelib import Tree,Node tree_clone = Tree() tree_id = 0 tree_id_str = str(tree_id) node_id_list = list() cursor = tree #tree_clone.create原创 2021-10-15 20:06:45 · 59 阅读 · 0 评论 -
清洗数据先把数据统一处理
虽然造成了时间复杂度的提升,但是思路清晰呀.def node_show(cursor): def name(child): return child.__class__.__name__ show_str = 'Node_name: {0}\n'.format(name(cursor)) content = list(ast.iter_fields(cursor))#以下程序就是解析这句话 for i in content: if isin原创 2021-10-15 19:33:36 · 90 阅读 · 0 评论 -
getattr中的...是省略号
print(name)print(getattr(cursor,name))print(getattr(type(cursor),name,...))--------------nameBootyBayBodyguardEllipsis原创 2021-10-15 19:24:46 · 45 阅读 · 0 评论 -
python的logging模块常用设置
我常用的调试设置,一般当print使用import logginglogging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(name)s %(levelname)s : %(message)s", datefmt = '%Y-%m-%d %H:%M:%S %a' )logging.debug('write what原创 2021-10-15 11:27:49 · 90 阅读 · 0 评论 -
python库文件夹中的__init__.py
以treelib为例C:\PROGRAMDATA\ANACONDA3\ENVS\PYTHON39\LIB\SITE-PACKAGES\TREELIB│ exceptions.py│ misc.py│ node.py│ plugins.py│ tree.py│ __init__.py要是没有init文件,有四种方式调用tree.py,都是最原始的方法import treelib.treeimport treelib.tree as treefrom arithmetic.t原创 2021-10-15 10:52:07 · 221 阅读 · 0 评论