Python数据结构

数据结构与算法(python)(数据结构) 整理了数据结构的基础内容,包括列表、栈和队列、链表、哈希表和树的相关知识点 阅读详情

排序

冒泡排序

# 用while循环实现
a = [5, 4, 3, 2, 1]
i = 0
while i < len(a) - 1:
    j = 0
    while j < len(a) - 1 - i:
        if a[j] > a[j+1]:
            a[j], a[j+1] = a[j+1], a[j]
        j += 1
    i += 1
# 用for循环实现
a = [5, 4, 3, 2, 1]
for i in range(len(a)-1):
    for j in range(len(a)-1-i):
        if a[j] > a[j+1]:
            a[j], a[j+1] = a[j+1], a[j]

插入排序

a = [5, 4, 3, 2, 1]
i = 1
while i < len(a):
    t = a[i]
    j = i - 1
    while j >= 0:
        if a[j] > t:
            a[j+1] = a[j]
        else:
            break
        j -= 1
    a[j+1] = t
    i += 1

选择排序

# 用while循环实现
a = [5, 4, 3, 2, 1]
i = 0
while i < len(a) - 1:
    min = i
    j = i + 1
    while j < len(a):
        if a[min] > a[j]:
            min = j
        j += 1
    if min != i:
        a[min], a[i] = a[i], a[min]
    i += 1
# 用for循环实现
a = [5, 4, 3, 2, 1]
for i in range(0, len(a)-1):
    min = i
    for j in range(i+1, len(a)):
        if a[min] > a[j]:
            min = j
    if min != i:
        a[min], a[i] = a[i], a[min]

快速排序

a = [5, 4, 3, 2, 1]
def partion(a, low, high):
    key = a[low]
    while low < high:
        while low < high and a[high] >= key:
            high -= 1
        a[low] = a[high]
        while low < high and a[low] <= key:
            low += 1
        a[high] = a[low]
    a[low] = key
    return low
def sort(a, low, high):
    if low < high:
        mid = partion(a, low, high)
        sort(a, low, mid-1)
        sort(a, mid+1, high)
sort(a, 0, len(a)-1)

查找

折半查找

a = [1, 2, 3, 4, 5]      # 列表要是有序的
def zheban(a, low, high, data):      # a为列表,low为起始位置,high为结束位置,data为要查找的元素
    while low <= high:
        mid = (low+high)//2
        if a[mid] == data:
            return mid
        elif a[mid] > data:
            high = mid - 1
        elif a[mid] < data:
            low = mid + 1
    return -1

折半查找(用递归的方法实现)

a = [1, 2, 3, 4, 5]      # 列表要是有序的
def dgzb(a, low, high, data):      # a为列表,low为起始位置,high为结束位置,data为要查找的元素
    if low <= high:
        mid = (low + high) // 2
        if a[mid] == data:
            return mid
        elif a[mid] < data:
            return dgzb(a, mid+1, high, data)
        elif a[mid] > data:
            return dgzb(a, low, high-1, data)
    return -1

链表

包含链表元素的插入、删除以及链表倒序

class Node():
    def __init__(self, num):
        self.num = num
        self.next = None
class LinkList():
    def __init__(self):
        self.head = None
    def append(self, node):      # 向链表中添加元素
        if self.head == None:
            self.head = node
        else:
            p = self.head
            while p.next != None:
                p = p.next
            p.next = node
    def insert(self):      # 向链表中插入元素
        n = int(input("请输入要插入的位置:"))
        data = int(input("请输入要插入的数据:"))
        if n == 1:
            one = Node(data)
            one.next = self.head
            self.head = one
        else:
            i = 1
            p = self.head
            while i < n - 1 and p != None:
                p = p.next
                i += 1
            if p == None:
                print("位置有误")
            else:
                one = Node(data)
                one.next = p.next
                p.next = one
    def delete(self):      # 删除链表中的元素
        if self.head == None:
            print("链表空了")
        else:
            n = int(input("请输入要删除的位置:"))
            if n == 1:
                print("您删除的元素是:", self.head.num)
                self.head = self.head.next
            else:
                i = 1
                p = self.head
                while i < n - 1 and p != None:
                    p = p.next
                    i += 1
                if p == None or p.next == None:
                    print("位置有误")
                else:
                    print("您删除的元素是:", p.next.num)
                    p.next = p.next.next
    def reverse(self):      # 链表倒序
        pre = None
        current = self.head
        next = self.head.next
        while next != None:
            current.next = pre
            pre = current
            current = next
            next = next.next
        current.next = pre
        self.head = current
    def dayin(self):      # 打印链表
        p = self.head
        while p != None:
            print(p.num, end=" ")
            p = p.next
        print("")
bbb = LinkList()
for i in range(1, 10):
    aaa = Node(i)
    bbb.append(aaa)
while True:
    bh = int(input("请输入编号:"))
    if bh == 1:
        bbb.insert()
    elif bh == 2:
        bbb.delete()
    elif bh == 3:
        bbb.dayin()
    elif bh == 4:
        bbb.reverse()
    elif bh == 0:
        exit(0)

循环队列

class Xhdl():
    def __init__(self, size):      # size为队列的长度
        self.queue = [None]*size
        self.tou = 0
        self.wei = 0
        self.size = size
    def rudui(self):
        if (self.wei + 1) % self.size == self.tou:
            print("满了")
        else:
            data = int(input("请输入入队元素:"))
            self.queue[self.wei] = data
            self.wei = (self.wei + 1) % self.size
    def chudui(self):
        if self.tou == self.wei:
            print("空了")
        else:
            print("出队元素是:", self.queue[self.tou])
            self.tou = (self.tou + 1) % self.size
    def dayin(self):
        if self.wei > self.tou:
            for i in range(self.tou, self.wei):
                print(self.queue[i], end=" ")
            print("")
        elif self.tou > self.wei:
            for i in range(self.tou, self.size):
                print(self.queue[i], end=" ")
            for i in range(self.wei):
                print(self.queue[i], end=" ")
            print("")
        else:
            print("空的")
dl = Xhdl(10)
while True:
    pd = int(input("请输入编号:"))
    if pd == 1:
        dl.rudui()
    elif pd == 2:
        dl.chudui()
    elif pd == 3:
        dl.dayin()
    else:
        exit(0)

 

【Python】数据结构 在编程的世界里,数据结构(Data Structures)是组织、管理和存储数据的方式。它们是算法的基础,是高效解决问题的关键。选择正确的数据结构,能够显著提升程序的性能、可读性和可维护性。Python作为一门高级编程语言,内置了多种强大且灵活的数据结构,如列表(List)、元组(Tuple)、字典(Dictionary)和集合(Set)。这些结构在日常开发中无处不在,理解它们的内部机制、性能特点及最佳实践,是成为Python高手的必经之路。数据结构是一种特定方式来组织和存储数据,以便可以高效地访问和修改数 阅读详情

相关推荐

Python数据结构简介

数据结构是计算机科学的基本概念,它有助于用任何语言编写高效的程序。Python是一种高级的,解释性的,交互式的和面向对象的脚本语言,与其他编程语言相比,我们可以用更简单的方式研究数据结构的基本原理。 在本章中,我们将学习一些常用数据结构的概述,以及它们与某些特定的Python数据类型的关系。还有一些特定于python的数据结构,它们被列为另一个类别。 一般数据结构 计算机科学中的各种数据结构大致分为以下两类。我们将在随后的章节中详细讨论以下每个数据结构。 1. 线性数据结构 这些是以顺序方式存储数据元素的数

777

关于python的循环队列,链表倒置,快速排序和链表环

循环队列: class XhDl(): def __init__(self,num): self.tou=0 self.wei=0 self.queue=[None]*num self.size=num def rudui(self): if (self.wei+1)%self.size==self.t...

qq_34681895的博客 703

Python数据结构实战

本文提供了Python在数据结构、数据库操作和Web开发中的实用实例集锦。数据结构部分涵盖列表、字典、集合等核心操作,包括反转、去重、排序等常见处理;数据库部分演示了Python与SQLite的交互,包含增删改查、事务处理等完整操作流程;Redis部分展示了键值操作、哈希表、发布订阅等NoSQL特性;Web开发部分则呈现了Flask、Django和FastAPI框架的典型应用场景。这些实例可直接用于项目开发或技术学习,覆盖了从基础操作到高级特性的完整技术栈。

keny-大成的博客 980

Python的数据结构

一. 认识Python数据结构 Python有4个内建的数据结构,它们可以统称为容器(container),因为它们实际上是一些“东西”组合而成的结构,而这些“东西”,可以是数字、字符甚至列表,或是它们的组合。 Python中的绝大部分数据结构可以被最终分解为三种类型:集合(Set),序列(Sequence),映射(Mapping)。这表明了数据存储时所需的基本单位,其重要性如同欧式几何公理之于...

zt_96123的博客 1万+

「Python系列」Python数据结构

这些数据结构提供了强大的功能,可以帮助你更有效地组织和操作数据。每种数据结构都有其适用的场景和优缺点,因此选择正确的数据结构对于编写高效和可维护的代码至关重要。元组和列表非常相似,但主要的区别在于元组是不可变的,而列表是可变的。这意味着一旦你创建了一个元组,就不能修改它,而列表可以在任何时候被修改。虽然元组是不可变的,但你可以通过元组解包(tuple unpacking)来轻松地将元组中的值赋给变量。虽然元组是不可变的,但你还是可以对它们进行一些操作,如连接、重复、索引、切片等。索引是从0开始的整数。

日常笔记/总结/系列知识梳理 1483

条码打印工具-Bartender的使用

文章目录1、安装Bartender1.解压安装包,可获得bartender2021版本和破解文本2. 双击“BarTender_2021_R1_Full_x64.exe”文件运行,勾选协议及软件安装设置3. 选择安装选项,自行选择勾选,点击Browser可更换软件安装路径4. 耐心等待软件安装完成,直接点击完成退出5. 此时会弹出提示需要激活许可证,先点击取消6. 接着将Crack夹中的“BarTend.exe”破解文件复制到软件安装目录中替换7. 再双击“serial.reg”导入注册,点击确定即可8.

暮紫的笔记本 1万+

python 数据结构篇

python中的数据结构实现:数组、链表(单链表、双向链表、双向循环链表)、队列(FIFO、LIFO/栈、优先级队列、双端队列)、树(二叉树、堆、树、森林)、图

qq_62047219的博客 2万+

手机也能跑大模型?QNN框架实战:从模型量化到Android部署全流程

本文详细介绍了如何利用QNN框架将大模型部署到Android手机端进行端侧推理。通过实战演示了从模型量化(如INT4/INT8混合精度)到Android应用集成的全流程,包括内存优化、性能调优及常见问题排查,帮助开发者实现大模型在资源受限设备上的高效本地运行。

joy55的博客 500

python数据结构与算法总结

python常用的数据结构与算法就分享到此处,本月涉及数据结构与算法的内容有如下文章: 《数据结构和算法对python意味着什么?》 《顺序表数据结构在python中的应用》 《python实现单向链表数据结构及其基本方法》 《python实现单向循环链表数据结构及其方法》 《python实现双向链表基本结构及其基本方法》 《python实现双向循环链表基本结构及其基本方法》 《py...

python之战 2万+

NVIDIA 2025 Board Design Engineer 校招笔试

电路分析,矩形波阶跃反馈驱动​,误差信号。非常简单,数电or​离散基础。第一题是考试规矩知情确认。大二暑假做的,纯体验​。五六题太长,下篇分享。

m0_74253823的博客 1129

基础知识学习 -- qnx 系统

qnx os车载系统

求变,从思想开始 3873

Python算法中常用的数据结构

数据结构可以帮助我们用于存储和操作复杂的数据。在Python中,数据结构有以下五类: ✨列表(list):可变的、有序元素序列。 ✨元组(tuple):不可变的、有序元素序列。 ✨集合(set):元素互斥的、可变的、无序元素序列。 ✨字典(dictionary):无序的、键值对序列。 ✨数据帧(DataFrame):存储二维数据的二维结构。

m0_73375411的博客 4339

python实现RsaWithSHA256签名以及国密Sm3WithSm2签名

【代码】python实现RsaWithSHA256签名以及国密Sm3WithSm2签名。

weixin_45005677的博客 3354

python中有哪些数据结构_python数据结构有哪些

python 数据结构 有哪些有没有用Python讲解数据结构和算法的书或者公开课对于python数据结构与算法重要吗对于任何语言来说,数据结构和算法都很重要。 你的这个问题不应该针对python这个语言问,而应该针对你的学编程的应用目的来问。 举个例子,如果你的学python的目的是做网站后台,毫无疑问你是要学数据结构和算法的; 如果你只是想在日常中写写短有哪些用 Python 语言讲算法和数据...

weixin_31715353的博客 500

CXL3.0 CDAT(Coherent Device Attributes Table)

在说明CDAT之前,先讲一下CXL中的DOE类型:CXL协议里定义了两种DOE的类型,一种是Compliance就是合规性测试的内容,还有一种就是CDAT(一致性属性表)Memory_Info_Valid是CXL设备的内存配置完成标志,位于DVSEC(Designated Vendor-Specific Extended Capability)的CXL Range X Size Low寄存器中(X为1或2)。

Summer的博客 1437

2、集中式MIMO雷达研究进展:正交波形设计与信号处理

集中式多输入多输出(Multiple Input Multiple Output,MIMO)雷达通常利用正交波形增加发射波形 自由度,采用数字阵列拓展空间收发自由度,使得雷达接收机的天线孔径获得明显扩展,最终带来空间分辨率、 测角精确度、杂波抑制能力等大幅度提升。但是,这些性能提升的前提是发射波形具有正交特性。事实上,在 实际应用中,在不牺牲时域/频域资源情况下,受限于时宽带宽积,无法获得完全正交的波形集合,从而限制了 MIMO雷达系统性能。本文对集中式MIMO雷达正交波形复用的技术原理进行了系统回顾,分别

qq_43416206的博客 2772

python数据结构概览,Python数据结构简介

数据结构是计算机科学的基本概念,它有助于用任何语言编写高效的程序。Python是一种高级的,解释性的,交互式的和面向对象的脚本语言,与其他编程语言相比,我们可以用更简单的方式研究数据结构的基本原理。在本章中,我们将学习一些常用数据结构的概述,以及它们与某些特定的Python数据类型的关系。还有一些特定于python的数据结构,它们被列为另一个类别。一般数据结构计算机科学中的各种数据结构大致分为以下...

weixin_34752204的博客 393

【3天快速入门WPF】1-从最简单的xaml开始

首先我们要知道xaml语法中声明即定义,意思就是“见到元素就相当于创建实例”,MainWindow.xaml的主干是一个元素里包含着一个 元素。这段程序就是在定义一个Window类的实例,这个实例的一个组成部分是一个Grid类的实例。

Zy100Papa的博客 1623

python基本数据结构

python基本数据结构 文章目录python基本数据结构什么是数据结构数据类型1. 栈2. 队列3. 链表3.1 单向链表3.2 双向链表4. 数组 什么是数据结构 简单来说,数据结果就是设计数据以何种方式 存储在计算机中 如:列表,集合,与字典等都是一种数据结构 程序 = 数据结构 + 算法 数据结构与数据类型 数据类型 说明:数据类型是一个值的 (集合和定义)在此集合上的一组操作(通常是增删改查或者操作读写的方法)的总称 数据类型:int、str、boolean、byte 数据结构 说明:数据以什么方

weixin_47073925的博客 3048

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

python数据结构有哪些_python数据结构

一:数据结构数据结构可以认为他们是用来处理一些数据的或者说是存储数据。对于数据结构的介绍会关系到类和对象的定义,此处对这两个定义加以描述。何为类:说道类首先我们能够想到类型,在数据结构中类型有哪些常用的类型有int整型,float浮点型,等。在Python中类是有方法的,我们可以简单理解为对这一类可以执行哪些操作。何为对象:对象就是实际定义的一个变量, i = 5 i的类型是int整型,对象就是i...

weixin_39673972的博客 216

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

数据结构(Python)

二叉搜索树(BST,Binary Search Tree),也称二叉排序树或二叉查找树二叉搜索树是一颗二叉树, 可以为空;如果不为空,满足以下性质:非空左子树的所有键值小于其根结点的键值。非空右子树的所有键值大于其根结点的键值。左、右子树本身也都是二叉搜索树。下面哪些是二叉搜索树, 哪些不是?二叉搜索树的特点:二叉搜索树的特点就是相对较小的值总是保存在左结点上, 相对较大的值总是保存在右结点上.那么利用这个特点, 我们可以做什么事情呢?

m0_68625595的博客 1893

深度学习工具包 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 数据结构

并且只能一次添加一个元素,并且只能在列表最后;

cliffordl的专栏 926

【python数据结构&算法篇】python数据结构

没什么说的。。。。当目录用吧。。。循环队列是一种利用数组(或固定长度存储结构)实现的队列,队列的头尾指针在到达数组末尾时会“环绕”到数组的起始位置,实现“首尾相连”的效果。这样可以充分利用数组空间,避免“假满”问题。

qxj2422640226的博客 1379

Python数据结构类型总结

数据结构是构建程序的基本结构,每个数据结构都提供了一种组织数据的特定方式,以便能更高效的访问数据,Python 在其标准库中附带了一组广泛的数据结构,本文主要介绍以下内容: (1)Python 标准库中内置了哪些常见的抽象数据类型 (2)最常见的抽象数据类型在Python中如何映射到具体的命名 (3)如何在各种算法中将抽象数据类型付诸实际使用 本文为Python数据结构指引,对于每类具体的数据结构细节没有详细阐述,可根据功能需求自行查找相关内容

weixin_45526117的博客 1057

python有哪几种数据结构_Python最常用的数据结构6种

Python最常用的数据结构6种:数字、字符串、列表、元组、字典和集合。其中最为常用的是数字、字符串、列表和字典。可以用type()查看数据类型;1、数字(number)用于存储数值。python3支持4种类型的数字:int(整数类型)、foat(浮点型)、bool(布尔类型)、complex(复数类型)。2、字符串(string)由数值、字母、下划线组成的一串字符,可以使用单引号(')、双引号(...

weixin_39885690的博客 4114
上一篇: Python中的闭包和装饰器
下一篇: Python打印输出等腰三角形和空心等腰三角形
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值