Python 技能提升(一)

Python实现微信跳一跳辅助App教程 图像识别技术是计算机视觉领域的核心,它使计算机能够通过各种算法理解图像内容。在微信跳一跳游戏中,图像识别主要用于识别游戏画面中的跳跃平台、分数显示以及游戏结束等关键元素。通过图像识别,我们可以获取游戏场景中的实时数据,为后续的自动化操作提供准确的输入。 阅读详情
```python

```

注释规范

# Add commit for you codes.
# The proper addition of comments is so beautiful.

from abc import abstractmethod


def add(a: int, b: int) -> int:
    # You can write some necessary notes here.
    # Such as the role of functions, the types and roles of parameters.
    #
    # But what we recommend more is to know the meaning of the name when naming.
    # So you don't have to write too many comments.
    #
    # It's important to remember to update your comments after you change the code.
    return a + b


# The following comments are superfluous.

a = 10  # Define a variable to be 10.
b = 90  # Define a variable to be 90.
res = add(a, b)  # Call the function and get the sum of the two.
print(res)  # Output calculation result

文档字符串规范

def execute():
    """Execute the action to make the file saved."""
    pass


def test(url: str):
    """This is a test function for string document.
    Some description here.
    Another description here.

    Note: The key point to note.

    Args:
        url: A string where to fetch the content from

    Returns:
        A string with UTF-8 encoded content provided by the site.

    Raises:
        ValueError: if url argument is not of the expected type (str).
    """
    pass


# Output Documentation String
print(execute.__doc__)
print(test.__doc__)

注解规范

class Circle:
    def __init__(self, radius):
        self.radius = radius
        self.area = 0


def area(radius: float) -> Circle:
    """Compute area of a Circle with given radius."""
    pass


# Show the annotation content of the function
print(area.__annotations__)  # {'radius': <class 'float'>, 'return': <class '__main__.Circle'>}

布局规范

# Different methods in a class should be separated by empty lines.
# This is more aesthetically pleasing, as in the following example.

class People:
    def eat(self):
        pass

    def walk(self):
        pass
    
# Appropriate blank lines make the code more elegant.

def calculate_the_number_of_rows_of_content_from(path: str) -> int:
    with open(path, 'r') as file:
        lines = file.readlines()

    count = 0
    for line in lines:
        if line.strip():
            count += 1

    return count

# A line of code should be limited to 75 characters.
# If you exceed that amount, you can use the "\" symbol to wrap the line.
# Or, if you use the () symbol, you can simply wrap the line.

def some_too_long_method_for_demo_and_specified_usage(first_arg, second_arg, \
                                                      third_arg, fourth_arg):
    pass

too_long_variable_for_demo_in_scenario_one = 1
too_long_variable_for_demo_in_scenario_two = 2
too_long_variable_for_demo_in_scenario_three = 3

result = (too_long_variable_for_demo_in_scenario_one
          + too_long_variable_for_demo_in_scenario_two
          + too_long_variable_for_demo_in_scenario_three)

# Tabs and 4 Spaces are not equal.
# We recommend using 4 Spaces for indentation instead of tabs.

num = int(input())
if num > 0:
    pass

# Here is our recommended format.

mylist = [
    1, 2, 3,
    4, 5, 6
]

断言 assert

def divide(x: int, y: int) -> float:
    assert y != 0, "错误:除数不能为零!"  # 此行代码大意是:我断言y一定不等于0,如果我预判错误,抛出错误字符串
    return x / y


print(divide(2, 0))

符号 _

for _ in range(5):  # We only care about cycling five times.
    print("Hello World")

my_dict = {'age': 18, 'name': 'Jack', 'hobby': 'code'}
for key, _ in my_dict.items():  # We are only concerned with its key.
    print(key)

Tree = ('green', 'plentiful', 'leaf')
color, _, _ = Tree  # We only care about color.

列表推导式

class Weight:
    def __init__(self, weight: int):
        self.weight = weight

    def __repr__(self):
        return f'weight: {self.weight}'


weight_instances = [Weight(n) for n in range(10)]
print(weight_instances)

过滤与映射

nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]

def is_odd_number(number: int) -> bool:  # 判断一个数是否为奇数
    return number % 2 == 1

def multiply_by_two(number: int) -> int:  # 将一个数乘以2
    return number * 2

odd_nums = filter(is_odd_number, nums)  # 过滤出奇数
map_nums = map(multiply_by_two, odd_nums)  # 将奇数乘以2

result = list(map_nums)
print(result)

# 上面代码可以用列表推导式完成

nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
res_nums = [res * 2 for res in nums if res % 2 == 1]
print(res_nums)

灵活切片与*号

my_list = ['a', 'b', 'c', 'd', 'e']

# 灵活切片法:

(ele_1, ele_2, remain) = my_list[0], my_list[1], my_list[2:]
print(remain)  # ['c', 'd', 'e']

(ele_1, middle, ele_2) = my_list[0], my_list[1:-1], my_list[-1]
print(middle)  # ['b', 'c', 'd']

(front, ele_1, ele_2) = my_list[0:-2], my_list[-2], my_list[-1]
print(front)  # ['a', 'b', 'c']


# 使用 * 号的方法

(ele_1, ele_2, *remain) = my_list
print(remain)  # ['c', 'd', 'e']

(ele_1, *middle, ele_2) = my_list
print(middle)  # ['b', 'c', 'd']

(*front, ele_1, ele_2) = my_list
print(front)  # ['a', 'b', 'c']

模拟 switch-case

import operator  # 内置模块


def calculator(var1, var2, symbol):
    operator_dict = {
        '+': operator.add,  # operator 模块里面的 加法函数
        '-': operator.sub,  # operator 模块里面的 减法函数
        '*': operator.mul,  # operator 模块里面的 乘法函数
        '/': operator.truediv  # operator 模块里面的 除法函数
    }
    return operator_dict.get(symbol)(var1, var2)  # 函数地址 + 括号 => 调用


print(calculator(10, 20, '*'))  # 200

温馨提示:在 Python 3.10 推出了 match-case,其功能比其他语言的 switch-case 更强大

推荐阅读:https://blog.youkuaiyun.com/wuShiJingZuo/article/details/134589275

装饰器 @dataclass

推荐阅读:https://www.cnblogs.com/wang_yb/p/18077397

from dataclasses import dataclass


@dataclass
class People:
    pass

字典推导式

from dataclasses import dataclass


@dataclass
class User:
    name: str
    email: str


list_of_users = [User('Bob', '168@qq.com'), User('Jack', '195@qq.com')]


# 普通的写法
emails_for_user = {}
for user in list_of_users:
    if user.email:
        emails_for_user[user.name] = user.email

print(emails_for_user)


# 字典推导的写法
emails_for_user = {user.name: user.email
                   for user in list_of_users if user.email}
print(emails_for_user)

字典的排序

d = {'a': 400, 'c': 200, 'b': 300, 'd': 100}
print(d.items())  # dict_items([('a', 400), ('c', 200), ('b', 300), ('d', 100)])


# 按照键进行排序(升序)
d_list = sorted(d.items())
print(d_list)  # [('a', 400), ('b', 300), ('c', 200), ('d', 100)]


# 按照值进行排序(升序)
rule = lambda x: x[1]
d_list = sorted(d.items(), key=rule)  # 这里的key的意思不是字典中的key,而是sorted()函数的一个参数,用来说明以哪个东西进行排序
print(d_list)  # [('d', 100), ('c', 200), ('b', 300), ('a', 400)]


# 按照值进行排序(降序)
d_list = sorted(d.items(), key=lambda x: x[1], reverse=True)
print(d_list)  # [('a', 400), ('b', 300), ('c', 200), ('d', 100)]

字典的组合

fruits_price_1 = {'apple': 10.5, 'orange': 8.8}
fruits_price_2 = {'banana': 2.8, 'orange': 9.5}
fruits_price_3 = {'watermelon': 5.5, 'orange': 10.8}

# 通过更新将字典组合起来
lastest_fruit_price = {}
lastest_fruit_price.update(fruits_price_1)
lastest_fruit_price.update(fruits_price_2)
lastest_fruit_price.update(fruits_price_3)
print(lastest_fruit_price)  # {'apple': 10.5, 'orange': 10.8, 'banana': 2.8, 'watermelon': 5.5}

# 使用星星符号**将字典组合起来(速度会更快,因为它背后做了优化)
lastest_fruit_price = {}
lastest_fruit_price = {
    **fruits_price_1,
    **fruits_price_2,
    **fruits_price_3
}
print(lastest_fruit_price)  # {'apple': 10.5, 'orange': 10.8, 'banana': 2.8, 'watermelon': 5.5}

优美的打印字典

from pprint import pprint

books_map = {'name': 'Python编程指南', 'author': 'Jack',
             'stars': 5, 'release-time': '2024-5-20',
             'info': {'content': 'Guide to Programming ', 'user': 1000}}

pprint(books_map)

"""
运行结果:

{'author': 'Jack',
 'info': {'content': 'Guide to Programming ', 'user': 1000},
 'name': 'Python编程指南',
 'release-time': '2024-5-20',
 'stars': 5}
 
"""

集合的运算

# 定义两个集合
programming_languages = {'C#', 'Go', 'Java', 'Python', 'Ruby'}
dynamic_languages = {'Ruby', 'Python', 'JavasScript', 'Lua'}

# 集合的
print(programming_languages | dynamic_languages)  # 并集
print(programming_languages & dynamic_languages)  # 交集
print(programming_languages - dynamic_languages)  # 差集1
print(dynamic_languages - programming_languages)  # 差集2
print(programming_languages ^ dynamic_languages)  # 对称差集

"""
运行结果:

{'Python', 'Lua', 'Ruby', 'Java', 'Go', 'C#', 'JavasScript'}
{'Ruby', 'Python'}
{'Go', 'C#', 'Java'}
{'JavasScript', 'Lua'}
{'Lua', 'Java', 'Go', 'C#', 'JavasScript'}

"""

# -------------- 案例演示 --------------

backend_developers = ['John', 'Rose', 'Jane', 'Steven']  # 前端人员
frontend_developers = ['Jack', 'Rose', 'Jane', 'Tom']  # 后端人员
full_stack_developers = []  # 全栈人员

# 筛选出全栈人员:

# 原始方法:
for developer in backend_developers:
    if developer in frontend_developers:
        full_stack_developers.append(developer)

# 利用集合的运算性质
full_stack_developers = list(set(backend_developers) & set(frontend_developers))

集合推导式

class Person:
    def __init__(self, name):
        self.name = name


person_list = [Person('Jack'), Person(None), Person('Tom'), Person('John'), Person(None)]
name_set = {person.name for person in person_list if person.name}
print(type(name_set), name_set)  # <class 'set'> {'Tom', 'Jack', 'John'}

集合处理 Counter

from collections import Counter

c = Counter("你好,世界!你好,编程")

print(c)
print(c.most_common(3))  # 出现最多共同点中的前3个
print(c.keys())
print(c.values())
print(list(c.elements()))

"""
运行结果:

Counter({'你': 2, '好': 2, ',': 2, '世': 1, '界': 1, '!': 1, '编': 1, '程': 1})
[('你', 2), ('好', 2), (',', 2)]
dict_keys(['你', '好', ',', '世', '界', '!', '编', '程'])
dict_values([2, 2, 2, 1, 1, 1, 1, 1])
['你', '你', '好', '好', ',', ',', '世', '界', '!', '编', '程']
"""

元组解包数据

# 使用元组解包数据
csv_file_row = ['Jack', '168@qq.com', 35]
(name, email, age) = csv_file_row
print(name, email, age)  # Jack 168@qq.com 35

# 使用 *元组 解包数据
group1 = ('Cat', 'Dog')
group2 = ('Eagle', 'Geese')
new_group = (*group1, *group2, 'Snake')
print(new_group)  # ('Cat', 'Dog', 'Eagle', 'Geese', 'Snake')


# 使用 *元组 解包数据
def display_users(*users):
    print(type(users))
    for user in users:
        print(user)


display_users('Dany', 'Bobby', 'Jacky')

# 运行结果:
# <class 'tuple'>
# Dany
# Bobby
# Jacky

元组与占位符_

# 巧用占位符
animal = ('Cat', 'Dog', 'Eagle', 'Geese', 'Tiger')

(first, second, _, _, _,) = animal
print(first, second)  # Cat Dog

(first, second, *_) = animal
print(first, second)  # Cat Dog

高效拼接字符串

list_of_str = ['Syntax Error', 'Network Error', 'File not found']

# 普通方法
concat_string = ''
for substring in list_of_str:
    concat_string += substring

# 高效方法
concat_string = ''.join(list_of_str)

论文超详细精读|万字:2s-AGCN 1. 提出了一种新的双流自适应图卷积网络(2S-AGCN)用于基于骨架的动作识别。**模型中的图的拓扑既可以统一地学习,也可以通过BP算法以端到端的方式单独学习。** 2. 提出了一种同时对**一阶和二阶信息(骨架的长度与方向)建模的双流框架**,在识别精度上有了显著的提高。 它将骨架数据的图结构参数化,并嵌入到网络中,与模型共同学习和更新。 3. 文章主要创新点有两个,一个是双流网络,另外一个是自适应。 阅读详情

相关推荐

【脑电绘图教程 2】使用Brainstorm进行脑电处理及源定位

Brainstorm 是一个开源应用程序,支持MEG、EEG、fNIRS、ECoG、深度电极和其他电生理学的数据分析,尤其用于MEG、EEG的源定位。Brainstorm的主要优点是其简单直观的图形界面,不需要进行任何编程,即可上手MEG、EEG分析,此外,它还支持多种数据类型(基本上EEGLab支持的,它都支持),并且具有数据批量处理功能,可以很方便的分析自己的数据。

qq_40735196的博客 1万+

python 可视化_提升你的Python可视化编程技能,一文学会图表添加参考线和区域...

前两次呢,已经和大家讨论了关于Python数据可视化的经典库matplotlib相关的东东,已经介绍了plot()、scatter()、xlim()、ylim()、xlabel()、ylabel()和grid()这几个函数哦,下面呢,咱们继续前两节的内容,继续和大家聊matplotlib库相关的函数哦!好啦,那咱们就开始聊聊吧!用matplotlib库的axhline()函数和axvline()函...

weixin_39624606的博客 428

PP生产订单的BADI增强 WORKORDER_UPDATE

我们的项目需求是: 1、 保存时检查工单BOM是否存在物料号相同的行项目,如果有则提示“物料& 重复,请检查工单BOM” 系统增强出口:PPCO0001,检查组件行项目是否有重复物料项 开始以为的增强增强看一下是用PPCO0001还是PPCO0007 后来找到了badi WORKORDER_UPDATE IF_EX_WORKORDER_UPDATE~BEFORE_UPDATE

ERP运维咨询(目标和成功) 4635

计划扎实提升测试技能的朋友--》这篇帖子不可不看!

前言 软件测试行业作为IT行业的一个重头戏,行业一直再进行快速发展,国内由以前的对软件测试不重视,到目前高薪诚聘测试开发工程师仍缺口巨大就可以看出来行业的趋势,在国内目前的趋势和环境下,作为测试工程师最应该的就是提升自己的能力,有能力就有前途(钱途)! 但是作为测试从业工作者本身来讲,我们国内目前还是主流的业务测试工程师居多,笔者有幸给一些大厂的测试工程师做过内训,发现有不少的测试工程师对于我...

挨踢~小先生 86

光伏发电系统模拟及其发电预测开源python工具pvlib

本文介绍光伏发电系统模拟及其发电预测开源python工具pvlib,以及举例介绍获取辐照度方法、光伏发电预测思路。

肖永威的专栏 1万+

TekTronix 高速信号完整性基础以及测试方法分析

如果信号速率比较高,则CTLE与FFE都无法满足要求,尤其是大于10G,比如USB3.1Gen2 10Gbps,PCIe4.0 16Gbps,这些场合都会采用DFE均衡,DFE的优点是,它既可以识别当前比特,并且可以判决前面的n个比特(Tap的阶数越高,看到的前面的比特数越多),根据前面比特的变化来计算出要处理当前比特所要变化的幅度,来补偿由于前面比特变化所引起的信号幅度的变化。10G以下,一般都不太关心这个串扰,高于10G的信号,会发现相互之间的串扰越来越明显,已经成为引起误码的重要的原因之一。

weixin_45365488的博客 4141

《正规军的Python进阶之路|Python技能树测评》

通过《Python技能树测评》判断自己在哪个级别: Python技能树测评【https://bbs.youkuaiyun.com/skill/python】 完整的【Python】学习体系,给你正规军的训练。 每个模块都有对应的分支内容,并且分支内容都分为:【参考资料】【练习题】【交流讨论】三个内容,我最喜欢的是练习题,之前都是非正规军的学习,没有系统训练过,现在有【Python技能树测评】 终于可以把之前散乱的知识点总结在一起了。 三个方向都很齐全,对于初级开发人员是非常友好的,一般的【Pytho

红目香薰 1989

【理解机器学习算法】之Clustering算法(Agglomerative Clustering)

是一种层次聚类算法,通过逐步合并或“聚集”它们来构建嵌套聚类。这种方法采用自底向上的方式构建聚类层次:它从将每个数据点作为单个聚类开始,然后迭代合并最接近的聚类对,直到所有数据点合并为一个聚类,或直到达到指定的聚类数量。优点:- 聚合聚类在距离和连接准则的选择上具有多样性,使其适用于各种数据集。- 它产生了一个层次结构,这对于不同规模的聚类数据结构是有信息量的。-缺点:- 对于大数据集来说,它可能计算成本高,因为它需要在每次迭代中计算和更新所有聚类对之间的距离。

Hyman Qiu 2688

探索Python编程世界:从入门到精通

Python 是一种高级编程语言,由 Guido van Rossum 在上世纪 90 年代初开发。它具有简洁的语法和强大的功能,适用于各种不同的应用场景,如 Web 开发、数据分析、人工智能等。与其他编程语言相比,Python 更加易于学习和使用,因此成为了很多初学者的首选。《自学 Python 一一编程基础、科学计算及数据分析第 2 版》是一本深入浅出的 Python 编程入门书籍,通过清晰的解释和丰富的示例,帮助读者从基础到进阶掌握 Python 编程技能。

优快云站内信: https://i.youkuaiyun.com/#/msg/chat/qyj19920704 1万+

人工智能混合编程实践:C++调用封装好的DLL进行异常检测推理

C++、Python、ONNX、人工智能、异常检测、Anomalib 2.1.0

FriendshipTang的博客 170

【Bug已解决】Failed to fetch version ECONNREFUSED 解决方案

方案适用场景推荐指数难度方案一:NODE_EXTRA_CA_CERTS代理/企业网关证书⭐⭐⭐⭐⭐低方案二:浏览器导出证书不知证书在哪⭐⭐⭐⭐中方案三:使用系统证书macOS 用户⭐⭐⭐⭐中方案四:关闭代理直连快速验证⭐⭐⭐低方案五:更新 Node.js证书列表过时⭐⭐⭐低方案六:同步系统时间时间偏差导致⭐⭐⭐低根本原因。

博客 9973

一人公司如何用AI技能蒸馏法构建自动化Excel处理助手

在数字化转型浪潮中,自动化处理已成为提升个人与团队效率的关键技术。其核心原理在于将重复性、规则明确的人工操作转化为可编程的流程,通过脚本或智能体自动执行。这项技术的价值在于解放人力,让从业者从繁琐事务中抽身,专注于高价值创造。在数据处理、客户服务、文档管理等场景中,自动化技术应用广泛。本文聚焦于一人公司或独立开发者的具体实践,探讨如何利用AI智能体框架与Python,将个人处理Excel报表、答复标准咨询等日常经验,通过“技能蒸馏”方法,封装为可复用的自动化技能(Skill)。文中以构建一个能自动提取销售数

weixin_30335353的博客 381

为什么先进工艺需要check那么多corner?

那么hold slack = launch clock path delay + data path delay - capture_clock_path_delay = -capture_clock_path_delay,也就是说,capture clock path delay越大,hold越难满足。而且,我们在设计的时候,一般clock频率都会过约,所以是有较大的margin的。有的foundry还会对rc的取值范围进行了约束,如cworst_T,采用的是1.5 sigma的取值范围。

芯冰乐 2086

通往python之路(一)

     忘记优快云上哪位牛人的推荐去了,我对python有了兴趣。看了某位网友的python学习笔记,我感到python的语法是如此的精炼,可功能却又如此强大,我更加兴趣盎然,决心使用python创一番天地。    这段时间忙着准备考研,疏忽了python。某天,搜索到了华莽,下载《深入python》一书后,我恢复了当时的激情,对着本,一口气看了几张。感觉水平提升不少,对编译的原理和编码规

Ritain的专栏 641

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

探索LeetCode Python解决方案:优化你的算法技能

探索LeetCode Python解决方案:优化你的算法技能 在这个数字化的时代,精通编程和算法是提升技术能力的关键,而LeetCode是一个极好的平台,提供了一系列的编程挑战来检验和提高这些技能。对于Python爱好者来说,项目为解决LeetCode上的问题提供了一套完整的Python解决方案。 项目简介 这个项目由吴佳阳创建,旨在整理并分享他在LeetCode上用Python解题的经验。它不仅...

gitblog_00012的博客 466

深度学习工具包 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辅助脚本实例分享

本文主要为大家整理了关于微信跳一跳的辅助脚本内容,这次我们给大家整理的是关于python的脚本内容,一起来学习下。这段时间微信跳一跳这个游戏非常火爆,但是上分又非常的难,对于程序员来说第一个念头就是通过写一个辅助脚本外挂让上分变的容易,python现在比较火,我们一起来以python语言为基础总结以下各路神仙写的关于跳一跳的辅助脚本,大家在学习的时候主要理解他们的写法思路,对你学习python非常...

weixin_39702559的博客 679

教你用Python来玩微信跳一跳

Python 2.7Android 手机Adb 驱动Python Matplot绘图。

Python栈 224

chatgpt赋能python:Python分割——字符串处理中的必备技能

Python中的分割是指将一个字符串根据特定的规则拆分为多个子串的过程,其中子串的个数和内容取决于规则的设置。本文由chatgpt生成,文章没有在chatgpt生成的基础上进行任何的修改。以上只是chatgpt能力的冰山一角。作为通用的Aigc大模型,只是展现它原本的实力。对于颠覆工作方式的ChatGPT,应该选择拥抱而不是抗拒,未来属于“会用”AI的人。🧡AI职场汇报智能办公文案写作效率提升教程 🧡专注于AI+职场+办公方向。下图是课程的整体大纲下图是AI职场汇报智能办公文案写作效率提升教程。

虚幻私塾 372

python去除csv某一列为空的数据

我整理的一些关于【CSV,Python】的项目学习资料(附讲解~~)和大家一起分享、学习一下:https://d.51cto.com/Hpqqk2Python去除CSV某一列为空的数据 CSV(逗号分隔值)文件是一种常见的用于存储表格数据的格式。在数据处理和分析中,清洗数据是必不可少的一步。尤其是当某一列的数据存在缺失值...

weixin_35370032的博客 527

CodeCombat终极指南:在编程学习中掌握技能的完整教程

CodeCombat是一个革命性的编程学习平台,通过互动式体验让编程学习变得既有趣又高效。这个开源教育工具将复杂的编程概念转化为直观的学习关卡,让学习者在使用Python、JavaScript等真实编程语言解决问题和完成挑战的过程中,真正掌握编码技能。无论你是编程新手还是希望提升技能的开发者,CodeCombat都能为你提供沉浸式的学习体验。 ## 🎯 为什么选择CodeCombat编程学习平

gitblog_00469的博客 1109

《Python项目开发实战》--熟悉Python基础后我能做什么?

在自学了200小时的Python后,突然有点不知道学什么了。基础的都差不多懂了,高级一点的部分怎么看也不太理解。真是到了小白阶段的瓶颈了。这几天只是在codecademy上学了一些Git,HTML&CSS,SQL,Python也没动过。今天突然翻开之前借来还没看的《Python项目开发实战》,看了前言,有几句话就已经深深的吸引我了,回答了我“熟悉Python基础后我能做什么?”的问题。现在摘录其中几

flyerooo的博客 8609

Learn Python The Hard Way (习题1)

虽然前期已通过自学,完成了python基础部份的学习,但是对于实践方面的实操较少。为了让自己在读下一本编程书籍前打下良好的基础,通过《笨办法学python》这本书复习并提高自已的编程能力,以跑例子为主,并进行相关知识点的归纳总结。(pycharm,版本是python3.8。) Python3与Python2在使用print时区别在于是否需要添加()。 > 习题 1: 第一个程序 print ("Hello World!") print ("Hello Again" ) print ("I like

weixin_47600357的博客 199

学点Python吧,别再这么累了

“我真的好累,真的好想辞职啊,可是……”转眼间,疫情都快一周岁了。看似一切都在好转,可实际上好多朋友都留言道,被刚刚恢复运转没多久的公司压榨地喘不过气来,每天都忙着同样的事情,却没有任何...

DevOps持续集成的博客 243

Python第二天

今天做最大间距。感觉还行,可以自己写下来。买了本流畅的Python 。过几天就到了,感觉Python技术还需提高。

weixin_50298414的博客 115

面试高分视频,教你一招利用Python快速去除图片水印,Python入门视频教程

我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了,只是里面的项目比较多,水平也是参差不齐,大家可以挑自己能做的项目去练练。这是我花了几天的时间去把Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。PIL也是一个Python 图像处理库,其中Image模块是在Python PIL图像处理中常见的模块,对图像进行基础操作的功能基本都包含于此模块内。

m0_62261166的博客 711

简单且有创意的python作品,python创意编程大赛作品

此书最大特点,每个项目附有最完整的代码,并且会很贴心的告诉你,如何运行程序:$ python playlist.py --common test-data/maya.xml test-data/rating.xml。通过此项目,学会使用turtle绘图的基本命令,最重要的是此书讲解如何计算出每个关键点,这是其他博客中难以看到的,博客中大都是堆积的代码,一个又一个晦涩难懂的数字。剩下的几个项目有,基本的图像处理类,3D图像处理类,黑客攻击类,趣味性十足!最后,再对每个项目总结一遍,非常贴心!

nbhkk的博客 518

又不是去做程序员,为什么要会Python?

为什么这么多岗位都要求掌握Python?这位猎头朋友给出的回答很特别:“你要知道,在企业招人的评判标准里,比起学历经验,公司更看重的是: 你个人的优势,能否给企业持续创造价值。”Python, 作为这几年最实用的职场技能,对各行业和岗位,都有很实际的帮助。

xx16755498979的博客 1003
上一篇: C++ 基于vs2019创建并使用动态链接库(dll)
下一篇: Python 技能提升(二)
code_stream
博客等级 码龄4年 1238粉丝 169原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值