python笔记-基础

读取.xls文件报错:XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b‘MIME-Ver 读取.xls文件报错:XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'MIME-Ver 阅读详情

目录

数据类型

可变VS不可变

tuple VS list VS dict VS set

list和str互相转换

字符串

字符串格式化

字典

遍历字典中的key、value

循环

self

with

函数

不定长参数

内建函数

zip()

isinstance()

自定义函数

匿名函数

面向对象

init

私有属性

继承

抽象类

时间

获取当前时间的秒格式时间戳

pytz

json

json.loads()/json.dumps()

demjson

校验json schema

断言

assert

常用tips

随机生成指定位数的字符串

截取指定位数的字符串

 判断一个字符串中包含多个字符串

 判断一个list包含另一个list

获取项目路径

__init__.py

if __name__ == '__main__'

统计list中各个元素出现的个数

报错总结

报错信息:TypeError: sequence item 0: expected str instance, int found

报错信息:json.decoder.JSONDecodeError: Expecting property name enclosed in double quo

报错信息:xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\xef\xbb\xbfaccou'

坑



数据类型

可变VS不可变

可变对象不可变对象
listint
dictfloat
setbool
str
tuple

tuple VS list VS dict VS set

tuplelistdictset
形式a = (1,2,3)a = [1,2,3]a ={"x": 1,"y":2}a ={1,2,3}
特点
  • 长度固定
  • 无法对元素进行增删改查
  • 存储空间小
  • 性能优
  • 长度不固定
  • 可以对元素进行增删改查
  • 存储空间比元组大(由于动态,需要存储指针)
  • 性能比元组差
  • 通过索引键访问
  • 性能高
  • 内部结构是哈希表
  • 不支持索引访问
  • 性能高
  • 内部结构是哈希表
互相转换tuple()list()
常用函数
  • 计算item出现的次数:count(item)
  • 计算item第一次出现的index:index(item)
  • 元素反转:reversed(tuple)
  • 排序:sorted(tuple)
  • 计算item出现的次数:count(item)
  • 计算item第一次出现的index:index(item)
  • 元素反转:reverse()
  • 排序:sort()
  • 增加键值对:a['z'] = "2"
  • 删除键值对:a.pop('x'),注意pop是删除字典中的最后一个元素,而字典是无序的,所以不知道会删除谁
  • 增加元素:a.add(item)
  • 删除元素:a.remove(item)
  • 排序:sorted(set)

list和str互相转换

1、list转str

  • ''.join(list)

eg:

list = [1, 2, 3, 4, 5]

''.join(list) 结果即为:12345

','.join(list) 结果即为:1,2,3,4,5

2、str转list

  • str.split(',')
  • list(str)

str转tuple

stra= “ell,sdsfd,sdfd”

listb = stra.split(',')

tuplec = tuple(listb)

字符串

python字符串支持三种引号的表达式,'、"、""",三种表达式的值完全一样,方便在字符串中嵌套引号

字符串格式化

方式f''str.format()%
用法举例

name = ’ABC‘

  • f’hello {name}'--->hello ABC
  • F'My name is {name.lower()}' --->My name is abc
  • f'result is {(lambda x: x ** 2 + 1) (2)}'

name = “ABC”

  • print("hello {}" .format(name))--->hello ABC
  • print('{0} {1} {0}'.format('hello','world'))---> hello world hello
  • print('{name}.format(name))---> ABC

name = “ABC”

  • print("hello %s!" %(name))--->hello ABC
说明
  • f-string,亦称为格式化字符串常量(formatted string literals),是Python3.6新引入的一种字符串格式化方法
  • 性能优于str.format()

字典

遍历字典中的key、value

for k,v in dict.items():
print(k,v)

循环

forwhile
特点性能>while需要在满足某个条件前,不停地重复某些操作,并且没有特定的集合需要去遍历,一般用 while 循环
说明


for item in iterable:
    if condition:
        expression1
    else:
        expression2

可简写成:
expression1 if condition else expression2 for item in iterable

self

  • self指的是类实例对象本身

  • 类方法必须包含参数 self,且为第一个参数,self 代表的是类的实例。

  • self 的名字并不是规定死的,也可以使用 this,但是最好还是按照约定是用 self。

  • 如果变量前面加了self,那么在任何实例方法(非staticmethod和calssmethod)就都可以访问这个变量

with

作用:使用了 with 语句,就不需要显式调用 close()。在 with 的语境下任务执行完毕后,close() 函数会被自动调用。

函数

不定长参数

不知道函数会传递多少个参数时可使用*args, **kwargs

eg:def wrapper(*args, **kwargs):

*args**kwargs
说明发送一个非键值对的可变数量的参数列表给一个函数将不定长度的键值对作为参数传递给一个函数
举例
def test_args(first, *args):
    print('Required argument: ', first)
    print(type(args))
    for v in args:
        print ('Optional argument: ', v)

test_args(1, 2, 3, 4)


---->
Required argument:  1
<class 'tuple'>
Optional argument:  2
Optional argument:  3
Optional argument:  4

def test_kwargs(first, *args, **kwargs):
   print('Required argument: ', first)
   print(type(kwargs))
   for v in args:
      print ('Optional argument (args): ', v)
   for k, v in kwargs.items():
      print ('Optional argument %s (kwargs): %s' % (k, v))

test_kwargs(1, 2, 3, 4, k1=5, k2=6)



---->
Required argument:  1
<class 'dict'>
Optional argument (args):  2
Optional argument (args):  3
Optional argument (args):  4
Optional argument k2 (kwargs): 6
Optional argument k1 (kwargs): 5

其他

  • kwargs 是 keyword arguments
  • args 是 arguments 的缩写
  • *args 必须放在 **kwargs 的前面
  • * 和 ** 表示解包

eg:元组解包后传给对应的实参

def test_args_kwargs(arg1, arg2, arg3):
    print("arg1:", arg1)
    print("arg2:", arg2)
    print("arg3:", arg3)

args = ("two", 3, 5)
test_args_kwargs(*args)

#result:
arg1: two
arg2: 3
arg3: 5

内建函数

zip()

作用:

  • 将可迭代的对象作为参数,将对象中对应的元素打包成一个个元组,然后返回由这些元组组成的列表。
  • 利用 * 号操作符,可以将元组解压为列表。

举例:

a = [1,2,3]

c = [4,5,6,7,8]

zipped = zip(a,c) 

----->zipped = [(1, 4), (2, 5), (3, 6)]       #元素个数=最短列表个数

zip(*zipped) 

----->[(1, 2, 3), (4, 5, 6)]            #*反解压

isinstance()

作用:判断类型

eg:

  • 判断是否为datetime类型:
isinstance(timeInput, datetime.datetime)

自定义函数

  • def 是可执行语句,这意味着函数直到被调用前,都是不存在的。当程序调用函数时,def 语句才会创建一个新的函数对象,并赋予其名字。
  • 主程序调用函数时,必须保证这个函数此前已经定义过。而在函数内部调用其他函数,函数间哪个声明在前、哪个在后就无所谓,因为 def 是可执行语句,函数在调用之前都不存在。
  • 函数的参数可以设定默认值。def func(param = 0):
  • Python 函数的另一大特性,支持函数的嵌套,指函数里面又有函数。

函数的嵌套能够保证内部函数的隐私。内部函数只能被外部函数所调用和访问,不会暴露在全局作用域。

合理的使用函数嵌套,能够提高程序的运行效率

嵌套函数中的内部函数可以访问外部函数定义的变量,但是无法修改,若要修改,必须加上 nonlocal 这个关键字

  • 在函数内部改变全局变量的值,必须加上 global 这个声明,告诉 Python 解释器,函数内部的变量 就是之前定义的全局变量
  • 闭包函数:闭包和嵌套函数类似,不同的是,闭包的外部函数返回的是一个函数,而不是一个具体的值

举例:

def nth_power(exponent):
    def exponent_of(base):
        return base ** exponent
    return exponent_of # 返回值是exponent_of函数

square = nth_power(2) # 计算一个数的平方
cube = nth_power(3) # 计算一个数的立方 
print(square(2))  # 计算2的平方
print(cube(2)) # 计算2的立方
# 输出
4 # 2^2
8 # 2^3

匿名函数

匿名函数 lambda常规函数 def
特点

lambda 专注于简单的任务

lambda 的主体是只有一行的简单表达式,并不能扩展成一个多行的代码块。

常规函数则负责更复杂的多行逻辑

匿名函数是个表达式,不是语句

  • lambda 可以用在列表内部
  • lambda 可作为函数的参数
  • 不能用在列表内部
  • 不能作为函数的参数
匿名函数在调用前无须被定义先定义函数才能调用函数(def 必须通过其函数名被调用)
优点简化代码复杂度
使用场景
  • 函数内容非常简短,只需要一行就能完成
  • 在程序中只被调用一次
  • 函数内容复杂
  • 需多次调用

面向对象

类对象属性函数
说明一群有着相似性的事物的集合

集合中的一个事物

由 class 生成的某一个 object

对象的某个静态特征对象的某个动态能力

静态方法类方法成员方法

装饰器

@staticmethod@classmethod无
特点
  • 通过类直接调用,不需要创建对象,不会隐式传递self
  • 代码可读性好:看到该标签就知道这个方法并不需要依赖对象本身的状态。
  • 节省内存空间,既然是与类实例无关自然就不用创建类实例对象。
  • 相当于一个相对独立的方法,跟类没有什么关系,只是在类的作用域里的函数而已
  • 至少需要一个cls参数
  • 类方法只能操作类本身的公有字段
  • 类成员方法无法访问实例变量但是可以访问类变量
第一个参数 self 代表当前对象的引用,可以通过此函数,来实现想要的查询 / 修改类的属性等功能。
适用场景

在方法中不需要访问任何实例方法和属性,纯粹地通过传入参数并返回数据的功能性方法,那么它就适合用静态方法来定义

实现不同的 init 构造函数

init

init表示构造函数,即一个对象生成时会被自动调用的函数。

私有属性

属性以 __ (注意,此处有两个 _) 开头,则为私有属性,不能在类的函数之外的地方被访问和修改。

继承

每个类都有构造函数,继承类在生成对象的时候,是不会自动调用父类的构造函数的,因此你必须在 init() 函数中显式调用父类的构造函数。它们的执行顺序是 子类的构造函数 -> 父类的构造函数。

抽象类

抽象类是一种特殊的类,它生下来就是作为父类存在的,一旦对象化就会报错。同样,抽象函数定义在抽象类之中,子类必须重写该函数才能使用。相应的抽象函数,则是使用装饰器 @abstractmethod 来表示。

时间

获取当前时间的秒格式时间戳

import time

int(time.time())

pytz

是什么:pytz是python的时区模块,常用于时区的转换

怎么用:常常配合datetime一起使用

datetime除了data方法生成的时间是没有时区概念,其他如time、datetime等都是有时区概念

其提供的对象方法为:

__all__ = [
    'timezone', 'utc', 'country_timezones', 'country_names',
    'AmbiguousTimeError', 'InvalidTimeError',
    'NonExistentTimeError', 'UnknownTimeZoneError',
    'all_timezones', 'all_timezones_set',
    'common_timezones', 'common_timezones_set',
]

eg:(更多参考:https://segmentfault.com/a/1190000019697169)

  • timezone:传入一个时区,如:Asia/Shanghai,返回一个时区对象
pytz.timezone('Asia/Shanghai')
>>> <DstTzInfo 'Asia/Shanghai' LMT+8:06:00 STD>
  • utc: 返回一个utc时区对象
pytz.utc
>>> <UTC>

eg:

# 秒格式时间戳转换成日期格式
def timestampToDate1(timestamp):
    timestamp_int = int(timestamp)
    tz = pytz.timezone(TIME_ZONE)
    dt = pytz.datetime.datetime.fromtimestamp(timestamp_int, tz)
    otherStyleTime = dt.strftime("%Y-%m-%d %H:%M:%S")
    return otherStyleTime

json

json.loads()/json.dumps()

json.loads()json.dumps()
说明

将字符串反序列化为字典类型

将字典序列化为 string类型
举例

import json

a='{"errno":0,"errmsg":null,"unassigned":0,"total":0,"list":null}'

a1=json.loads(a)

-->a1={'errno':0,'errmsg':None,'unassigned':0,'total':0,'list':None}

import json

a='{"errno":0,"errmsg":null,"unassigned":0,"total":0,"list":null}'

a2=json.dumps(a)

-->a2="{'errno':0,'errmsg':None,'unassigned':0,'total':0,'list':None}"

demjson

是什么:编码或解码JSON格式的库

作用:解决不正常的json格式字符串的转换

demjson两个常用的方法:

  • encode:将 Python 对象编码成 JSON 字符串

  • decode:将  JSON 字符串解码成python对象

eg:

import demjson



py_json="{x:1, y:2, z:3}"

py_json1 = "{'x':1, 'y':2, 'z':3}"

data = demjson.decode(py_json)

#  ------>   {'y': 2, 'x': 1, 'z': 3}

data1 demjson.decode(py_json1)

#  ------>   {'y': 2, 'x': 1, 'z': 3}



data2 = json.loads(py_json)

# ---->报错:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes

几个tips:

  • demjson 2.2.4 兼容python2和python3,Setuptools从版本58.0.0开始不再支持2to3的builds,所以会导致 demjson 2.2.4安装后不再可用,可降级setuptools版本:

        pip install --upgrade setuptools==57.5.0

校验json schema

使用Free Online JSON to JSON Schema Converter将json字符串转换成json schema(注意开vpn)

from jsonschema import validators


schema = {
                          "$schema": "http://json-schema.org/draft-04/schema#",
                          "type": "object",
                          "properties": {
                            "data": {
                              "type": "object",
                              "properties": {
                                "eid": {
                                  "type": "integer"
                                },
                                "sid": {
                                  "type": ["string","null"]
                                }
                                  },
                                  "required": [
                                    "eid",
                                    "sid"
                                    
                                  ]
                                
                          },
                          "required": [
                            "data"
                           
                          ]
                        }




va = validators.Draft4Validator(schema)
va.validate(response)

断言

assert

  • assert xx :判断 xx 为真
  • assert not xx :判断 xx 不为真
  • assert a in b :判断 b 包含 a
  • assert a == b :判断 a 等于 b
  • assert a != b :判断 a 不等于 

eg:

断言某个字符串包含于某段字符串:assert (expectation['response']['message'] in response['message'])

常用tips

随机生成指定位数的字符串

import string

ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 8))

截取指定位数的字符串

str[a:b]        #注意范围是前闭后开

 判断一个字符串中包含多个字符串

p = "Tom is a boy,Lucy is a girl,they all like english!"
keywords= 'Tom,Lucy'
filters= ["boy","like"]
print all(f in p for f in filters)
>>>True
print all([w in p and w for w in keywords.split(',')])
>>>True

 判断一个list包含另一个list

a = ['cc','ss','dd']
b = ['dd','aa','ss','cc']

                            
if set(a) < set(b):
    print("true")
else:
    print("false")




>> true

获取项目路径

对于一个独立的项目,所有的模块的追寻方式,最好从项目的根目录开始追溯,即相对的绝对路径。

获取当前程序所在位置的上级目录:

        sys.path.append("..")

获取项目项目的路径:

        dir = os.path.join(sys.path[1], '')

__init__.py

在 Python 2 规范中,用来表述包对外暴露的模块接口

在 Python 3 规范中,__init__.py 并不是必须的

if __name__ == '__main__'

作用:想把一个东西封装成模块,又想让它可以执行,就将要执行的代码放在 if __name__ == '__main__'下面。

原因:因为import 在导入文件的时候,会自动把所有暴露在外面的代码全都执行一遍,__name__ 就会被赋值为该模块的名字,不等于 __main__,所以import时不会执行if __name__ == '__main__'下面的代码。

eg:import该模块时不会打印“testing”,只有运行该模块时才会打印“testing”

def get_sum(a, b): 
    return a + b

if __name__ == '__main__': 
    print('testing')

统计list中各个元素出现的个数

三种方法:

1、利用dict字典

a = [1, 2, 3, 1, 1, 2]
dict = {}
for key in a:
    dict[key] = dict.get(key, 0) + 1
print dict



>>>{1: 3, 2: 2, 3: 1}
lists = [1, 2, 3, 4, 5, 6, 7, 5, 4, 3, 2, 12] 
dicts = {x: lists.count(x) for x in set(lists)}
print(dicts)





>>> {1: 1, 2: 2, 3: 2, 4: 2, 5: 2, 6: 1, 7: 1, 12: 1}

2、利用collection包下Counter的类

from collections import Counter
a = [1, 2, 3, 1, 1, 2]
result = Counter(a)
print result


>>>{1: 3, 2: 2, 3: 1}

3、利用pandas包下的value_counts方法

import pandas as pd
a = [1, 2, 3, 1, 1, 2]
result = pd.value_counts(a)
print result



>>>1    3
   2    2
   3    1

报错总结

报错信息:TypeError: sequence item 0: expected str instance, int found

eg:

list1=[1,'two','three',4]

print(','.join(list1))

报错:

Traceback (most recent call last):
  File "", line 1, in
    print(" ".join(list1))
TypeError: sequence item 0: expected str instance, int found

原因:list包含数字,不能直接转化成字符串。

解决:print(" ".join('%s' %id for id in list1))

报错信息:json.decoder.JSONDecodeError: Expecting property name enclosed in double quo

原因:str转换成json的时候,写了单引号

解决:把单引号改成双引号

报错信息:xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\xef\xbb\xbfaccou'

原因:csv文件直接修改后缀名,改成xls,导致读取excel文件失败

解决:重新保存csv文件,保存成xls格式即可

坑

  • python3.6之前,字典是无序的,所以用for循环时,输出的顺序!=写入的顺序,可以用:d1 = collections.OrderedDict()将字典变成有序的

参考文档:

xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b‘\xb4\xfa\xc2 错误:xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\xb4\xfa\xc2\xeb\t\xc3\xfb\xb3' ecxcl 的表格不是 问题与此页问题一致: 整个没有解决怎么解决windows平台下python 中xlrd模块对97-03 xls文件无法读取数据的问题 - OSCHINA - 中文开源技术交流社区​​​​​1我用xlrd对excel文件进行数据读取,对0 阅读详情

相关推荐

小甲鱼《零基础入门学习Python》学习笔记

根据老师的建议,现在将第二次复习小甲鱼的《零基础入门学习Python》而做的学习笔记,上传到网上,方便今后复习和保存,因为是手写的,所以做了扫描锐化处理,方便阅读。 ...

baidu_32335419的博客 1万+

python xlrd读取文件报错_Python使用xlrd读Excel文件时报错

问题描述原始脚本报错信息XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '\xef\xbb\xbf原因分析从这个错误提示看,不像是脚本问题,而是Excel文件本身的格式错误导致的。提示的意思就是期望的是BOF开头记录,但是读到的是'\xef\xbb\xbf果真,以右键文本方式打开该文件,内容全是标...

weixin_39989190的博客 2274

Python基础学习笔记

前言:本片笔记是本人之前学习时所记录的笔记,通篇纯手打,部分图片借鉴黑马与开源程序员ppt课件与开源中国网站 一、python基础 1.1 基础知识 1.1.1 注释 注释:在程序中对程序代码进行解释说明的文字。 作用:注释不是程序,不能被执行,只是对程序代码进行解释说明,让别人可以看懂程序代码的作用,能够大大增强程序的可读性。 单行注释:以  #开头,#右侧 的所有文字当做说明,而不是真正要执行的程序,起辅助说明作用; 多行注释:以一对三个双引号引起来(“”“注释内容”“”)来解释说明一段代码

shgg2917的博客 2143

python import xlrd 报错_Python 使用xlrd读Excel文件报错

Python 使用xlrd读Excel文件报错:XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '\xef\xbb\xbf

weixin_42222065的博客 1254

Python基础 笔记2

Python基础 笔记2一、笔记说明二、代码部分三、转载说明 一、笔记说明 本博客专栏《Python基础》的所有笔记均为.py格式文件,复制后均可无误执行(注意修改文件路径,每个人的工作区不一样)。 在复制代码时,若代码段标明了文件名称,即该笔记包含多个文件,请注意每个代码段标明的文件名称,并在本地创建文件夹以便于运行。 代码运行环境Python3.7.9,建议使用Pycharm2020.1作为编辑器,使用Anaconda3作为包管理器。 二、代码部分 三、转载说明 本文内容完全原创,文章完成时间

魔菲赫伯特的博客 152

InSAR_ISCE软件数据处理流程之:利用哨兵数据获取2015年尼泊尔地震同震形变场

ISCE软件数据处理流程之:利用哨兵数据获取2015年尼泊尔地震同震形变场 ISCE软件做干涉只需要将数据准备好,并配置好insarApp.xml文件即可进行。 一、数据准备 1、SAR数据获取 本利中使用的数据为欧空局提供的sentinel-1A/B数据,可从阿拉斯加数据服务器上下载,具体下载方法可参考: 哨兵数据下载方法. 2、哨兵卫星轨道文件下载 哨兵数据处理除了需要SAR影像外,还需提供轨道参数文件,可从https://qc.sentinel1.eo.esa.int/aux_poeorb/下载。下载

weixin_42128764的博客 1万+

Unsupported format, or corrupt file: Expected BOF record; found b‘[Localiz‘

写在前面 批量解析execl文件,循环异常停止,报错RT 异常定位耗费较多时间,大多无果,特此记录 问题解决 异常描述: xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '\xd6\xb8\xb1\xea\\\xc8\xd5\xc6' Unsupported form...

kngines 9898

从原理到实现:在《图灵完备》中构建一个144*256像素、1536时钟刻/帧的视频播放器

本文详细解析了在《图灵完备》游戏中构建144*256像素、1536时钟刻/帧视频播放器的全过程。从图灵完备原理出发,通过分层架构设计、视频数据预处理和关键电路实现,展示了如何用基础电子元件模拟现代显卡功能。重点介绍了像素坐标定位系统和颜色数据处理流水线的优化方案,为游戏内复杂电子系统设计提供实践指导。

weixin_42520025的博客 445

Python基础系列教程1-python笔记

本人在基础阶段的python学习笔记,秉持互联网分享精神为各位同僚特供参考。在记录过程中也参考了很多大佬和机构的笔记。仅供个人学习,尊重劳动成果。

深度学习 442

FISCO BCOS 三、多群组部署以及新节点加入群组

本章主要以星形组网和并行多组组网拓扑为例,指导您了解如下内容:了解如何使用创建多群组区块链安装包;了解创建的多群组区块链安装包目录组织形式;学习如何启动该区块链节点,并通过日志查看各群组共识状态;学习如何向各群组发送交易,并通过日志查看群组出块状态;了解群组内节点管理,包括节点入网、退网等;了解如何新建群组。

qq_63235624的博客 2921

如何获取不同分区模板的基因表达矩阵,abagen: Allen 大脑图谱遗传数据工具箱的使用笔记

基因表达从根本上塑造了人类大脑的结构和功能结构。像Allen人脑图谱这样的开放获取转录组数据集提供了前所未有的能力来检查这些机制。abagen工具箱,这是一个用于处理转录组学数据的开放获取软件包,并使用它来检查方法可变性如何影响使用Allen人脑图谱的研究结果。

从事脑科学核磁共振方法学研究,在Nature communications等权威期刊发表研究论文,熟练掌握磁共振处理方法和统计学方法,欢迎大家和我交流。 3340

Python3基础学习笔记资源下载

Python3基础学习笔记资源下载 去发现同类优质开源项目:https://gitcode.com/ 欢迎来到本仓库!这里提供了《Python3基础学习笔记.pdf》资源文件的下载。 简介 《Python3基础学习笔记.pdf》是一个专为Python初学者准备的宝贵学习资料。本笔记详细介绍了Python 3.4的基本语法和高级特性,内容系统全面,旨在帮助读者快速掌握Python编程的基础知识。 内...

gitblog_06706的博客 345

uniapp - 如何跟内嵌 web-view 组件内的网页交互,与 web-view 内嵌网页进行双向通信(uniapp 与 webview 网页之间的 “相互“ 传值)提供详细的示例代码及解决方案

uni-app如何实现在H5环境中与web-view中的网页交互通讯uniappuni-app 与 web-view内嵌网页 双向通信 如何跟内嵌web-view交互uniappAPP与webview子页面交互uniappAPP与webview子页面交互关于uni-app 使用 web-view 页面之间互相跳转、通信等问题uniapp的web-view嵌入网页,网页与uniapp通信webview如何与uniapp写的H5页面交互嵌套webview调用uniapp各种API组件实现H5和app通讯和交互

✅ 精选推荐文章 1万+

Python基础知识 - 导图笔记【二】

Python基础的重要性不言而喻,它是掌握这门强大编程语言的关键。扎实的基础知识能够帮助初学者快速理解更复杂的编程概念和技术。因此,精通Python基础不仅能够提高编程效率,还能为深入学习高级技术打下坚实的基础,是每个程序员成长道路上的重要一步。本文是在学习Python基础知识时所做的笔记和思维导图。可供给新人在学习过程中使用的资料,我是靠自学而来,非计算机专业,懂得初入学者的在学习中的难点痛点。

weixin_54482667的博客 412

S7-200 SMART PLC 子程序功能块(阀门控制)

由于S7-200 SMARTPLC的子程序种种功能、容量限制,有时想实现多次调用的子程序可能并不是太容易,这篇博客还是给出一些推荐写法,供大家参看。

RXXW_Dor的博客 8071

ISP算法:自动白平衡(AWB)

1. 为什么要做白平衡? 人类视觉系统具有颜色恒常性特点,一次人类对物体观察不受光源影响。但是Sensor在不同光线下,物体呈现的颜色不同,在晴朗天空下会偏蓝,在烛光下会偏红。如图: 2.什么是自动白平衡? 为了消除光源对于图像传感器成像的影响,模拟人类视觉系统的颜色恒常性。保证在任何场景下看到的白色是真正的白色。 3. 如何做自动白平衡? 只要乘以一个对角矩阵,便可以进行白平衡...

a200800170331的专栏 1万+

Python基础笔记:为零基础学习Python提供高效路径

Python基础笔记:为零基础学习Python提供高效路径 去发现同类优质开源项目:https://gitcode.com/ 项目介绍 《Python基础笔记》是一个专门为零基础、对Python语言充满兴趣的学习者打造的开源笔记资料。这份资源详尽地介绍了Python编程的基础知识和技能,帮助初学者在短时间内快速上手,构建扎实的编程基础。 项目技术分析 《Python基础笔记》涵盖了Python语言...

gitblog_06744的博客 413

【Linux0.11代码分析】之 系列文章链接汇总(全)

【Linux0.11代码分析】00 之 系列文章链接汇总(全)

|~~~热爱生活、努力学习的小伙汁~~~| 1450

Python 基础 学习笔记

BHK 2302

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

python基础笔记

python基础使用语法

2402_87768817的博客 1317

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Python基础day10学习笔记回顾

凋落的枫叶 224

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

python基础个人笔记

无返回值只是我们没有定义返回值,拿属性去接无返回值函数时,属性值为None# 函数定义# 有参有返回值return msg# 无参无返回值test_print1("你好")

Tom_House的博客 867

Python3基础学习笔记资源获取:为零基础学习Python提供完美起点

Python3基础学习笔记资源获取:为零基础学习Python提供完美起点 去发现同类优质开源项目:https://gitcode.com/ Python作为一种流行的编程语言,其易学易用的特性吸引了许多初学者。今天,我们要为大家推荐一个开源项目——《Python3基础学习笔记资源获取》,它为Python初学者提供了一个宝贵的学习资源。以下是对这个项目的详细介绍。 项目介绍 《Python3基础学习...

gitblog_06701的博客 379

【Python】基础(学习笔记)

Python 推导式是一种独特的数据处理方式,可以从一个数据序列构建另一个新的数据序列的结构体列表(list)推导式字典(dict)推导式集合(set)推导式元组(tuple)推导式迭代:用来访问集合(字符串,列表或元组对象)元素迭代器:一个可以记住遍历的位置的对象迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束(只能往前不会后退)iter()和next()it1 = iter(list) # 创建迭代器对象。

wmh的博客 561

python基础语法看一篇就够了,全网最全python语法笔记汇总

如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。今天给大家分享一份师兄在自学过程中总结的 “python基础语法汇总笔记word版” 内容精炼全面,对于初学者来说十分有用,时不时翻看一下强化记忆,梳理知识难点。因为是可编辑文件,大家也可以把自己需要的知识点添加进去,成为自己独有的完整语法笔记。很多刚入门的小伙伴对于python语法记不住,写代码不知道从哪开始入手,今天整理了(python语法合集),随时随地学习@萌新语法。

WANGJUNAIJIAO的博客 167

Python零基础详细笔记

如果你。

m0_74317850的博客 915
上一篇: Git笔记
下一篇: Mysql笔记
sssammmm
博客等级 码龄9年 369粉丝 42原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值