随笔分类 - Python人工智能
摘要:def now(): print('2015-3-25') def log(text): print('Jason') def de0(func): print("111111111111") def decorator1(func): print('Cool') def wrapper(*args
阅读全文
摘要:def get_layer_output(model, image): ori_output = copy.deepcopy(model.graph.output) for node in model.graph.node: for output in node.output: model.grap
阅读全文
摘要:# _*_coding: utf-8_*_ import numpy as np import os import sys def listDirectory(path,list_path,filetype): for file in os.listdir(path): file_path=os.p
阅读全文
摘要:import os def batch_rename_files(directory, old_prefix, new_prefix): for filename in os.listdir(directory): if filename.startswith(old_prefix): basena
阅读全文
摘要:清除.txt文件中所有的0行 import sys try: file_in = sys.argv[1] except: file_in = 'in.txt' try: file_out = sys.argv[2] except: file_out = 'out.txt' with open(fil
阅读全文
摘要:安装TensorFlow 可以参考 https://tensorflow.google.cn/hub/installation?hl=zh_cn https://tensorflow.google.cn/install/pip?hl=zh-cn#windows 非GPU版本安装: pip insta
阅读全文
摘要:文件处理 文件操作: #打开文件 #python 里使用 open 内置函数打开并操作一个文件 # open 参数介绍 # file :用来指定打开的文件(不是文件的名字,而是文件的路径) # mode :打开文件时的模式,默认是r只读,默认使用rt(只读文本模式打开) # encoding :打开
阅读全文
摘要:面向对象的基本语法 定义类:类名怎么定义?使用 class来定义一个类class类名: 类名一般需要遵守大驼峰命名法,每一个单词的首字母都大写 1.class<类名> 2.class<类名>(object): eg: 小明今年18岁,身高1.75,每天早上跑完步,会去吃东西 小美今年17岁,身高1.
阅读全文
摘要:导入模块的语法 模块:在Python里一个py文件,就可以理解为以摸块 不是所有的py文件都能作为一个模块来导入 如果想要让一个py文件能够被导入,模块名字必须要遵守命名规则 Python为了方便我们开发,提供了很多内模块 1.使用import模块名直接导入一个模块 import time 2.fr
阅读全文
摘要:计算一段代码的执行时间 import time #time模块可以获取当前的时间 思路如下: #代码运行之前获取一下时间 start = time.time() #time模块里的time方法,可以获取当前时间的时间戳,时间戳是从1970-01-01 00:00:00 UTC 到现在的秒数 prin
阅读全文
摘要:定义函数 函数三要素: 函数名 参数 返回值 在Python里使用def来声明一个函数(定义格式如下:) def 函数名(参数): """ 多行注释,用于解释说明函数的作用 """ 函数要执行的操作 return(元组) Remark: 函数声明时,括号里的参数我们称之为形式参数,简称形参 形参的值
阅读全文
摘要:set的使用 集合(set)是一个无序的不重复元素序列,可以使用大括号(}或者set()函数创建集合。(如果有重复的数据,会自动去除) 创建格式: parame ={value0l,value02,....}或者set(value) 注意:空集合表示方式不是{},{}表示的是空字典, 空集合必须使用
阅读全文
摘要:#可变数据类型和不可变数据类型 python里的数据都是保存在内存里的,python里的数据又分为可变类型和不可变类型: 1不可变数据类型:字符串、数字、元组,如果修改值,内存地址会发生变化; 2可变数据类型:列表、字典、集合,如果修改值,内存地址不会发生变化 我们可以使用内置函数可以获取到一个变量
阅读全文
摘要:交换两个数有四种方法 1.a = a+b b = a-b a = a-b 2.a = a^b b = a^b a = a^b 3.a ,b = b ,a (Python独有) 4.c =a a = b b = c ##冒泡排序(优化) 1. list = [9, 8, 7, 6, 5, 4, 3,
阅读全文
摘要:安装requests库出错: ###WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 我们可以通过以下方法来解决 访问网
阅读全文
摘要:字符串创建 可以使用以下三种方式创建字符串 a='字符串内容' b="字符串内容" c='''字符串内容''' d=""" 字符串内容 """ 其中,如果3,4两种没有为变量赋值为字符串的内容,则表示是注释 注意: ' ' 和 " " 需要成对使用 字符串之间的连接 Python转义字符 | 转义字
阅读全文
摘要:print内置函数 def print(self, *args, sep=' ', end='\n', file=None): # known special case of print """ print(value, ..., sep=' ', end='\n', file=sys.stdout
阅读全文

浙公网安备 33010602011771号