简洁易懂,初学者挑战学习Python编程30天 (四)

目录

  • 第 21 天 - 类和对象
    • 21.1创建一个类
    • 21.2创建对象
    • 21.3类构造函数
    • 21.4对象方法
    • 21.5对象默认方法
    • 21.6修改类默认值的方法
    • 21.7继承
    • 21.8Overriding parent method
  • 第 22 天 - 网页抓取
    • 22.1什么是网页抓取
  • 第 23 天 - 虚拟环境
    • 23.1设置虚拟环境
  • 第 24 天 - 统计
    • 24.1统计数据
    • 24.2什么是数据?
    • 24.3统计模块
    • 24.4NumPy
    • 24.5导入 NumPy
    • 24.6使用创建 numpy 数组
    • 24.7创建 float numpy 数组
    • 24.8创建布尔 numpy 数组
    • 24.9使用numpy创建多维数组
    • 24.10将 numpy 数组转换为列表
    • 24.11从元组创建numpy数组
    • 24.12numpy 数组的形状
    • 24.13numpy数组的数据类型
    • 24.14numpy 数组的大小
    • 24.15使用numpy进行数学运算
    • 24.16添加
    • 24.17减法
    • 24.18乘法
    • 24.19分配
    • 24.20模数;找到余数
    • 24.21楼层划分
    • 24.22指数
    • 24.23检查数据类型
    • 24.24转换类型
    • 24.25多维数组
    • 24.26从 numpy 数组中获取项目
    • 24.27切片 Numpy 数组
    • 24.28如何反转行和整个数组?
    • 24.29反转行列位置
    • 24.30如何表示缺失值?
    • 24.31生成随机数
    • 24.32生成随机数
    • 24.33Numpy 和统计
    • 24.34numpy中的矩阵
    • 24.35numpy numpy.arange()
    • 24.36使用 linspace 创建数字序列
    • 24.37NumPy 统计函数与示例
    • 24.38如何创建重复序列?
    • 24.39如何生成随机数?
    • 24.40线性代数
    • 24.41NumPy 矩阵乘法与 np.matmul()
  • 第 25 天 - Pandas
    • 25.1安装pandas
    • 导入pandas
    • 25.2使用默认索引创建 Pandas 系列
    • 25.3使用自定义索引创建 Pandas 系列
    • 25.4从字典创建 Pandas 系列
    • 25.5创建一个常量 Pandas 系列
    • 25.6使用 Linspace 创建 Pandas 系列
    • 25.7数据帧
      • 从列表列表创建数据帧
    • 25.8使用字典创建 DataFrame
    • 25.9从字典列表创建数据帧
    • 25.10使用 Pandas 读取 CSV 文件
    • 25.11数据探索
    • 25.12修改数据帧
    • 25.13创建数据帧
    • 25.14添加新列
    • 25.15修改列值
    • 25.16格式化 DataFrame 列
    • 25.17检查列值的数据类型
    • 25.18布尔索引

简洁易懂,初学者挑战学习Python编程30天 (四)_第1张图片

你们的三连(点赞,收藏,评论)是我持续输出的动力,感谢。
在兴趣中学习,效益超乎想象,有趣的源码与学习经验,工具安装包,欢迎加我的微信:bobin1124,一起交流学习与分享。

第 21 天 - 类和对象

Python 是一种面向对象的编程语言。Python 中的一切都是一个对象,有它的属性和方法。程序中使用的数字、字符串、列表、字典、元组、集合等是相应内置类的对象。我们创建类来创建一个对象。一个类就像一个对象构造函数,或者是创建对象的“蓝图”。我们实例化一个类来创建一个对象。类定义了对象的属性和行为,而另一方面,对象代表了类。

从这个挑战一开始,我们就在不知不觉中处理类和对象。Python 程序中的每个元素都是一个类的对象。让我们检查一下python中的所有东西是否都是一个类:

asabeneh @ Asabeneh:~ $ python 
Python  3.96(默认,2021628 日 ,152621[11.0 0.0(铛- 1100.033.8)在 达尔文
式 的“帮助”,“版权”,“信用” 或 “许可” 的 更多 信息。
>> >  num  =  10 
>> >  type ( num )
 < class  'int' > 
>> >  string  =  'string' 
>> >'STR' > 
>> > 布尔 =>> > 类型(布尔)
 <'布尔' > 
>> >  LST  = []
 >> > 型(LST)
 <'列表' > 
>> >  TPL  =)
 >> > 类型( tpl )
 < class  'tuple' > 
>> > SET1  = 集()
>> > 类型(set1)
 < class  'set' > 
>> >  dct  = {
     }
 >> > 类型(dct)
 < class  'dict' >

21.1创建一个类

要创建一个类,我们需要关键字类,后跟名称和冒号。类名应该是CamelCase。

#语法
类类名:
  代码在这里

例子:

类 人:
  通过
打印(人)
< __main__.Person 对象在 0x10804e 510>

21.2创建对象

我们可以通过调用类来创建一个对象。

p  =()
打印( p )

21.3类构造函数

在上面的例子中,我们从 Person 类创建了一个对象。然而,没有构造函数的类在实际应用中并没有真正的用处。让我们使用构造函数使我们的类更有用。与Java或JavaScript中的构造函数一样,Python也有内置的init ()构造函数。的初始化构造函数有自参数这对类的当前实例的引用
实施例:

class  Person :
       def  __init__ ( self , name ):
         # self 允许将参数附加到类
          self。姓名 =姓名

p  =  Person ( 'Asabeneh' )
打印( p . name )
打印( p )
#输出
阿萨贝内
< __main__.Person 对象在 0x2abf46907e 80>

让我们向构造函数添加更多参数。

class  Person :
       def  __init__ ( self , firstname , lastname , age , country , city ):
           self。名字 = 名字
          自我。姓氏 = 姓氏
          自我。年龄 = 年龄
          自我。国家 = 国家
          自我。城市 = 城市


p  =  Person ( 'Asabeneh' , 'Yetayeh' , 250 , 'Finland' , 'Helsinki' )
 print ( p . firstname )
 print ( p . lastname )
 print ( p . age )
 print ( p . country )
 print ( p .城市)
#输出
阿萨贝内
耶塔耶
250
芬兰
赫尔辛基

21.4对象方法

对象可以有方法。方法是属于对象的函数。

例子:

class  Person :
       def  __init__ ( self , firstname , lastname , age , country , city ):
           self。名字 = 名字
          自我。姓氏 = 姓氏
          自我。年龄 = 年龄
          自我。国家 = 国家
          自我。city  =  city 
      def  person_info ( self ):
        返回 f' {
       自我。名字}  {
       自我。姓氏}{
        self。年龄}岁。他住在{
       自我。城市}{
       自我。国家} '

p  = 人('Asabeneh''Yetayeh'250'芬兰''赫尔辛基')
打印(p。person_info())
#输出
Asabeneh Yetayeh 已经 250 岁了。他住在芬兰赫尔辛基

21.5对象默认方法

有时,您可能希望为对象方法设置默认值。如果我们在构造函数中给参数赋予默认值,就可以避免在不带参数的情况下调用或实例化我们的类时出错。让我们看看它的外观:

例子:

class  Person :
       def  __init__ ( self , firstname = 'Asabeneh' , lastname = 'Yetayeh' , age = 250 , country = 'Finland' , city = 'Helsinki' ):
           self。名字 = 名字
          自我。姓氏 = 姓氏
          自我。年龄 = 年龄
          自我。国家 = 国家
          自我. 城市 = 城市

      def  person_info ( self ):
        返回 f' {
        self . 名字}  {
       自我。姓氏}{
        self。年龄}岁。他住在{
       自我。城市}{
       自我。国家} .'

P1  = 人()
打印(P1。person_info())
 P2  = 人('约翰''李四'30'Nomanland' , “诺曼城市)
打印(P2。person_info())
#输出
Asabeneh Yetayeh 已经 250 岁了。他住在芬兰赫尔辛基。
约翰·多伊今年 30 岁。他住在诺曼兰的诺曼城。

21.6修改类默认值的方法

在下面的例子中,person 类,所有的构造函数参数都有默认值。除此之外,我们还有技能参数,我们可以使用方法访问它。让我们创建 add_skill 方法来将技能添加到技能列表中。

class  Person :
       def  __init__ ( self , firstname = 'Asabeneh' , lastname = 'Yetayeh' , age = 250 , country = 'Finland' , city = 'Helsinki' ):
           self。名字 = 名字
          自我。姓氏 = 姓氏
          自我。年龄 = 年龄
          自我。国家 = 国家
          自我. 城市 = 城市
          自我。技能 = []

      def  person_info ( self ):
        返回 f' {
        self . 名字}  {
       自我。姓氏}{
        self。年龄}岁。他住在{
       自我。城市}{
       自我。国家} .' 
      def  add_skill(自我,技能):
          自我。技能。追加(技能)

p1  =  Person ()
打印( p1 . person_info ())
 p1 . add_skill ( 'HTML' )
 p1。add_skill ( 'CSS' )
 p1。add_skill('的JavaScript' )
 P2  = 人('约翰''李四'30'Nomanland' , “诺曼城市)
打印(P2。person_info())
印刷(P1. 技能)
打印(p2。技能)
#输出
Asabeneh Yetayeh 已经 250 岁了。他住在芬兰赫尔辛基。
约翰·多伊今年 30 岁。他住在诺曼兰的诺曼城。
[ ' HTML '' CSS '' JavaScript ' ]
[]

21.7继承

使用继承,我们可以重用父类代码。继承允许我们定义一个继承父类的所有方法和属性的类。父类或超类或基类是提供所有方法和属性的类。子类是从另一个类或父类继承的类。让我们通过继承person类来创建一个student类。

班级 学生(人):
通过

S1  = 学生('Eyob''Yetayeh'30'芬兰''赫尔辛基')
 S2  = 学生('了Lidiya''Teklemariam'28'芬兰''埃斯波')
印刷(S1。person_info( ))
 s1。add_skill ( 'JavaScript' )
 s1。add_skill ( '反应' )
 s1。'Python' )
打印( s1 .技能)

打印(S2。person_info())
 S2。add_skill ( '组织' )
 s2。add_skill ( '营销' )
 s2。add_skill ( '数字营销' )
打印( s2 . Skill )
输出
Eyob Yetayeh 30 岁。他住在芬兰赫尔辛基。
[ ' JavaScript '' React '' Python ' ]
Lidiya Teklemariam 28 岁。他住在芬兰的埃斯波。
[ “组织”、“营销”、“数字营销” ]

我们没有在子类中调用init ()构造函数。如果我们没有调用它,那么我们仍然可以从父级访问所有属性。但是如果我们确实调用了构造函数,我们就可以通过调用super来访问父属性。
我们可以向子类添加新方法,也可以通过在子类中创建相同的方法名称来覆盖父类方法。当我们添加init ()函数时,子类将不再继承父类的init ()函数。

21.8Overriding parent method

类 学生(人):
    高清 __init__(自我,名字= 'Asabeneh' ,姓氏= 'Yetayeh' ,年龄= 250,全国= '芬兰,城市= '赫尔辛基',性别= '男'):
        自我。性别 = 性别
        超()。__init__(名字,姓氏,年龄,country , city )
     def  person_info ( self ):
        性别 =  'He'  if  self。性别 == '男' 否则 '她'
        返回 f' {
        self . 名字}  {
       自我。姓氏}{
        self。年龄}岁。{
       性别}生活在{
       自我。城市} , {
       自己. 国家} .'

s1  =  Student ( 'Eyob' , 'Yetayeh' , 30 , 'Finland' , 'Helsinki' , 'male' )
 s2  =  Student ( 'Lidiya' , 'Teklemariam' , 28 , 'Finland' , 'Espoo' , 'female' ' )
打印( s1 . person_info ())
 s1 . add_skill ( 'JavaScript' )
 s1。s1。add_skill('Python的)
印刷(S1,技能)

打印(S2。person_info())
 S2。add_skill ( '组织' )
 s2。add_skill ( '营销' )
 s2。add_skill ( '数字营销' )
打印( s2 . Skill )
Eyob Yetayeh 30 岁。他住在芬兰赫尔辛基。
[ ' JavaScript '' React '' Python ' ]
Lidiya Teklemariam 28 岁。她住在芬兰的埃斯波。
[ “组织”、“营销”、“数字营销” ]

我们可以使用 super() 内置函数或父名 Person 来自动继承其父级的方法和属性。在上面的例子中,我们Overriding parent method的方法。child 方法有一个不同的特点,它可以识别性别是男性还是女性并指定适当的代词(他/她)

第 22 天 - 网页抓取

22.1什么是网页抓取

互联网充满了可用于不同目的的大量数据。为了收集这些数据,我们需要知道如何从网站上抓取数据。

网页抓取是从网站中提取和收集数据并将其存储在本地机器或数据库中的过程。

在本节中,我们将使用 beautifulsoup 和 requests 包来抓取数据。我们使用的包版本是beautifulsoup 4。

要开始抓取网站,您需要请求、beautifoulSoup4和网站。

pip 安装请求
pip 安装 beautifulsoup4

要从网站抓取数据,需要对 HTML 标签和 CSS 选择器有基本的了解。我们使用 HTML 标签、类或/和 ID 定位来自网站的内容。让我们导入 requests 和 BeautifulSoup 模块

进口 请求
从 BS4 进口 BeautifulSoup

让我们为要抓取的网站声明 url 变量。

 来自bs4 的导入请求
import BeautifulSoup url = 'https://archive.ics.uci.edu/ml/datasets.php'   
  

# 让我们使用 requests 的 get 方法从 url 中获取数据

响应 = 请求。get ( url )
 # 让我们检查状态
status  =  response。status_code 
print ( status ) # 200 表示获取成功
200

使用beautifulSoup解析页面内容

 来自bs4 的导入请求
import BeautifulSoup url = 'https://archive.ics.uci.edu/ml/datasets.php'   
  

响应 = 请求。获取(网址)
内容 = 响应。content  # 我们从网站上获取所有内容
soup  =  BeautifulSoup ( content , 'html.parser' ) # beautiful 
Soup将有机会解析print ( soup . title ) # UCI Machine Learning Repository: Data Sets</标题></span>
打印(汤。标题。get_text())#UCI机器学习库:数据集
打印(汤。体)#给网站上的整个页面
打印(响应。STATUS_CODE)

桌子 <span class="token operator">=</span> 汤。find_all <span class="token punctuation">(</span> <span class="token string">'table'</span> <span class="token punctuation">,</span> <span class="token punctuation">{
     </span> <span class="token string">'cellpadding'</span> <span class="token punctuation">:</span> <span class="token string">'3'</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
 <span class="token comment"># 我们的目标是 cellpadding 属性值为 3 的表格</span>
<span class="token comment"># 我们可以选择使用 id、class 或 HTML 标签,更多信息请查看beautifulsoup doc </span>
table  <span class="token operator">=</span> 表<span class="token punctuation">[</span> <span class="token number">0</span> <span class="token punctuation">]</span> #,结果是一个列表,我们是从它取出数据
为 TD 在 表。找到(<span class="token string">'tr'</span>)。find_all <span class="token punctuation">(</span> <span class="token string">'td'</span> <span class="token punctuation">)</span><span class="token punctuation">:</span>
    打印<span class="token punctuation">(</span> td <span class="token punctuation">.</span> text<span class="token punctuation">)</span>
</code></pre> 
  <p>如果你运行这段代码,你可以看到提取已经完成了一半。</p> 
  <p>你很特别,每天都在进步。您距离通往伟大的道路只剩下八天了。<br> 恭喜! </p> 
  <h1>第 23 天 - 虚拟环境</h1> 
  <h2>23.1设置虚拟环境</h2> 
  <p>从项目开始,最好有一个虚拟环境。虚拟环境可以帮助我们创建一个孤立或分离的环境。这将帮助我们避免跨项目的依赖冲突。如果您在终端上编写 pip freeze ,您将在计算机上看到所有已安装的软件包。如果我们使用 virtualenv,我们将只访问特定于该项目的包。打开终端并安装 virtualenv</p> 
  <blockquote> 
   <p>asabeneh@Asabeneh: ~ $ pip install virtualenv</p> 
  </blockquote> 
  <p>在 30DaysOfPython 文件夹中创建一个 flask_project 文件夹。</p> 
  <p>安装 virtualenv 包后,转到您的项目文件夹并通过编写以下内容创建一个虚拟环境:</p> 
  <p>对于 Mac/Linux:</p> 
  <pre><code class="prism language-python">asabeneh@Asabeneh<span class="token punctuation">:</span> <span class="token operator">~</span> <span class="token operator">/</span>Desktop<span class="token operator">/</span>30DaysOfPython<span class="token operator">/</span>flask_project \$ virtualenv venv
</code></pre> 
  <p>对于 Windows:</p> 
  <pre><code class="prism language-python">C:\Ú SERS \Ú SER \ d ocuments \ <span class="token number">3</span> 0DaysOfPython \˚F lask_project <span class="token operator">></span>蟒<span class="token operator">-</span>m VENV VENV
</code></pre> 
  <p>我更喜欢将新项目称为 venv,但可以随意使用不同的名称。让我们检查 venv 是否是通过使用 ls(或 dir 用于 Windows 命令提示符)命令创建的。</p> 
  <pre><code class="prism language-python">asabeneh@Asabeneh:<span class="token operator">~</span> <span class="token operator">/</span>Desktop<span class="token operator">/</span>30DaysOfPython<span class="token operator">/</span>flask_project$ ls


静脉<span class="token operator">/</span>
</code></pre> 
  <p>让我们通过在我们的项目文件夹中编写以下命令来激活虚拟环境。</p> 
  <p>对于 Mac/Linux:</p> 
  <pre><code class="prism language-python">asabeneh@Asabeneh<span class="token punctuation">:</span> <span class="token operator">~</span> <span class="token operator">/</span>Desktop<span class="token operator">/</span>30DaysOfPython<span class="token operator">/</span>flask_project$ source venv<span class="token operator">/</span><span class="token builtin">bin</span><span class="token operator">/</span>activate
</code></pre> 
  <p>在 Windows 中激活虚拟环境可能非常依赖于 Windows Power shell 和 git bash。</p> 
  <p>对于 Windows 电源外壳:</p> 
  <pre><code class="prism language-python">C:\Ú SERS \Ú SER \ d ocuments \ <span class="token number">3</span> 0DaysOfPython \˚F lask_project <span class="token operator">></span> VENV \ S cripts \一个ctivate
</code></pre> 
  <p>对于 Windows Git bash:</p> 
  <pre><code class="prism language-python">C:\Ú SERS \Ú SER \ d ocuments \ <span class="token number">3</span> 0DaysOfPython \˚F lask_project <span class="token operator">></span> VENV \ S cripts \。启用
</code></pre> 
  <p>编写激活命令后,您的项目目录将以 venv 开头。请参阅下面的示例。</p> 
  <p>(venv) asabeneh@Asabeneh: ~ /Desktop/30DaysOfPython/flask_project$<br> 现在,让我们通过编写 pip freeze 来检查这个项目中的可用包。您将看不到任何包。</p> 
  <p>我们将要做一个Flask小项目,所以让我们将Flask包安装到这个项目中。</p> 
  <pre><code class="prism language-python"><span class="token punctuation">(</span>venv<span class="token punctuation">)</span> asabeneh@Asabeneh<span class="token punctuation">:</span> <span class="token operator">~</span> <span class="token operator">/</span>Desktop<span class="token operator">/</span>30DaysOfPython<span class="token operator">/</span>flask_project$ pip install Flask
</code></pre> 
  <p>现在,让我们编写 pip freeze 来查看项目中已安装包的列表:</p> 
  <pre><code class="prism language-python"><span class="token punctuation">(</span>venv<span class="token punctuation">)</span> asabeneh@Asabeneh<span class="token punctuation">:</span> <span class="token operator">~</span> <span class="token operator">/</span>Desktop<span class="token operator">/</span>30DaysOfPython<span class="token operator">/</span>flask_project$ pip freeze
点击<span class="token operator">==</span><span class="token number">7.0</span>
Flask<span class="token operator">==</span><span class="token number">1.1</span><span class="token number">.1</span>
它的危险<span class="token operator">==</span><span class="token number">1.1</span><span class="token number">.0</span>
Jinja2<span class="token operator">==</span><span class="token number">2.10</span><span class="token number">.3</span>
标记安全<span class="token operator">==</span><span class="token number">1.1</span><span class="token number">.1</span>
Werkzeug<span class="token operator">==</span><span class="token number">0.16</span><span class="token number">.0</span>
</code></pre> 
  <p>完成后,您应该使用deactivate 停用活动项目。</p> 
  <pre><code class="prism language-python"><span class="token punctuation">(</span>venv<span class="token punctuation">)</span> asabeneh@Asabeneh<span class="token punctuation">:</span> <span class="token operator">~</span> <span class="token operator">/</span>Desktop<span class="token operator">/</span>30DaysOfPython$ 停用
</code></pre> 
  <p>安装了使用Flask的必要模块。现在,您的项目目录已准备好用于Flask项目。<br> 恭喜! </p> 
  <h1>第 24 天 - 统计</h1> 
  <h2>24.1统计数据</h2> 
  <p>统计学是研究数据的收集、组织、显示、分析、解释和呈现的学科。统计学是数学的一个分支,建议作为数据科学和机器学习的先决条件。统计学是一个非常广泛的领域,但我们将在本节中只关注最相关的部分。完成此挑战后,您可以进入 Web 开发、数据分析、机器学习和数据科学路径。无论您走哪条路,在您职业生涯的某个阶段,您都会获得可以处理的数据。拥有一些统计知识将帮助您根据数据做出决策,数据如他们所说。</p> 
  <h2>24.2什么是数据?</h2> 
  <p>数据是为某种目的(通常是分析)收集和翻译的任何字符集。它可以是任何字符,包括文本和数字、图片、声音或视频。如果数据没有放在上下文中,它对人或计算机没有任何意义。为了让数据有意义,我们需要使用不同的工具处理数据。</p> 
  <p>数据分析、数据科学或机器学习的工作流程始于数据。可以从某个数据源提供数据,也可以创建数据。有结构化和非结构化数据。</p> 
  <p>可以以小格式或大格式找到数据。我们将获得的大多数数据类型已在文件处理部分中介绍。</p> 
  <h2>24.3统计模块</h2> 
  <p>Python统计模块提供了计算数值数据的数理统计的函数。该模块无意成为第三方库(如 NumPy、SciPy)或面向专业统计学家(如 Minitab、SAS 和 Matlab)的专有全功能统计软件包的竞争对手。它针对图形和科学计算器的级别。</p> 
  <h2>24.4NumPy</h2> 
  <p>在第一部分中,我们将 Python 本身定义为一种出色的通用编程语言,但在其他流行库(numpy、scipy、matplotlib、pandas 等)的帮助下,它成为了一个强大的科学计算环境。</p> 
  <p>NumPy 是 Python 科学计算的核心库。它提供了一个高性能的多维数组对象,以及用于处理数组的工具。</p> 
  <p>到目前为止,我们一直在使用 vscode,但从现在开始我会推荐使用 Jupyter Notebook。要访问 jupyter notebook,让我们安装anaconda。如果您使用的是 anaconda,则大多数常用软件包都已包含在内,如果您安装了 anaconda,则您没有安装软件包。</p> 
  <pre><code class="prism language-python">asabeneh@Asabeneh<span class="token punctuation">:</span> <span class="token operator">~</span> <span class="token operator">/</span>Desktop<span class="token operator">/</span>30DaysOfPython$ pip install numpy
</code></pre> 
  <h2>24.5导入 NumPy</h2> 
  <p>如果您支持 jupyter notebook,则可以使用Jupyter notebook</p> 
  <pre><code class="prism language-python">  <span class="token comment"># 如何导入 numpy </span>
    <span class="token keyword">import</span>  numpy  <span class="token keyword">as</span>  np 
    <span class="token comment"># 如何检查 numpy 包的版本</span>
    <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'numpy:'</span> <span class="token punctuation">,</span> np <span class="token punctuation">.</span> __version__ <span class="token punctuation">)</span>
     <span class="token comment"># 检查可用方法</span>
    <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token builtin">dir</span> <span class="token punctuation">(</span> np <span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
  <h2>24.6使用创建 numpy 数组</h2> 
  <p><strong>创建 int numpy 数组</strong></p> 
  <pre><code class="prism language-python">  <span class="token comment"># 创建 python 列表</span>
    python_list  <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span>

    <span class="token comment"># 检查数据类型</span>
    <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'Type:'</span> <span class="token punctuation">,</span> <span class="token builtin">type</span> <span class="token punctuation">(</span> python_list <span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment"># <class 'list'> </span>
    <span class="token comment"># </span>
    <span class="token keyword">print</span> <span class="token punctuation">(</span> python_list <span class="token punctuation">)</span> <span class="token comment"># [1, 2, 3, 4, 5]</span>

    二维列表 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span> <span class="token number">6</span> <span class="token punctuation">,</span> <span class="token number">7</span> <span class="token punctuation">,</span> <span class="token number">8</span> <span class="token punctuation">]</span><span class="token punctuation">]</span>

    打印(二维列表)   <span class="token comment"># [[0, 1, 2], [3, 4, 5], [6, 7, 8]]</span>

    <span class="token comment"># 从 python 列表创建 Numpy(Numerical Python) 数组</span>

    numpy_array_from_list  <span class="token operator">=</span>  np。array <span class="token punctuation">(</span> python_list <span class="token punctuation">)</span>
     <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token builtin">type</span> <span class="token punctuation">(</span> numpy_array_from_list <span class="token punctuation">)</span><span class="token punctuation">)</span>    <span class="token comment"># <class 'numpy.ndarray'> </span>
    <span class="token keyword">print</span> <span class="token punctuation">(</span> numpy_array_from_list <span class="token punctuation">)</span> <span class="token comment"># array([1, 2, 3, 4, 5])</span>
</code></pre> 
  <h2>24.7创建 float numpy 数组</h2> 
  <p>使用浮点数据类型参数从列表创建浮点 numpy 数组</p> 
  <pre><code class="prism language-python">  <span class="token comment"># Python 列表</span>
    python_list  <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span>

    numy_array_from_list2  <span class="token operator">=</span>  np。阵列(python_list,D型细胞<span class="token operator">=</span>浮动)
    打印(numy_array_from_list2)#阵列(<span class="token punctuation">[</span><span class="token number">1</span>,<span class="token number">2</span>,<span class="token number">3</span>,<span class="token number">4</span>,<span class="token number">5</span><span class="token punctuation">]</span>)
</code></pre> 
  <h2>24.8创建布尔 numpy 数组</h2> 
  <p>从列表创建一个布尔值 numpy 数组</p> 
  <p>numpy_bool_array = np。数组([ 0 , 1 , - 1 , 0 , 0 ], dtype = bool )<br> 打印( numpy_bool_array ) # 数组([假, 真, 真, 假, 假])</p> 
  <h2>24.9使用numpy创建多维数组</h2> 
  <p>一个 numpy 数组可能有一个或多个行和列</p> 
  <pre><code class="prism language-python">  two_Dimension_list  <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span> <span class="token number">6</span> <span class="token punctuation">,</span> <span class="token number">7</span> <span class="token punctuation">,</span> <span class="token number">8</span> <span class="token punctuation">]</span><span class="token punctuation">]</span>
     numpy_two_dimensional_list  <span class="token operator">=</span>  np。数组(二维列表)
    打印(类型(numpy_two_dimensional_list))
    打印(numpy_two_dimensional_list)
</code></pre> 
  <p><类’ numpy.ndarray ’ ><br> [[0 1 2]<br> [3 4 5]<br> [6 7 8]]</p> 
  <h2>24.10将 numpy 数组转换为列表</h2> 
  <pre><code class="prism language-python"><span class="token comment"># 我们总是可以使用 tolist() 将数组转换回 Python 列表。</span>
np_to_list  <span class="token operator">=</span>  numpy_array_from_list。tolist()
打印(类型(np_to_list))
打印(<span class="token string">'一个维阵列:'</span>,np_to_list)
打印(<span class="token string">'二维阵列:'</span>,numpy_two_dimensional_list。tolist())
</code></pre> 
  <pre><code class="prism language-python">   <span class="token operator"><</span>类<span class="token string">'列表'</span> <span class="token operator">></span>
    一维数组:<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span>
    二维数组:<span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
</code></pre> 
  <h2>24.11从元组创建numpy数组</h2> 
  <pre><code class="prism language-python"><span class="token comment"># Numpy array from tuple </span>
<span class="token comment"># 在 Python 中创建元组</span>
python_tuple  <span class="token operator">=</span> <span class="token punctuation">(</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">)</span>
 <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token builtin">type</span> <span class="token punctuation">(</span> python_tuple <span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment"># <class 'tuple'> </span>
<span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'python_tuple: '</span> <span class="token punctuation">,</span> python_tuple <span class="token punctuation">)</span> <span class="token comment"># python_tuple: ( 1, 2, 3, 4, 5)</span>

numpy_array_from_tuple  <span class="token operator">=</span>  np。array <span class="token punctuation">(</span> python_tuple <span class="token punctuation">)</span>
 <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token builtin">type</span> <span class="token punctuation">(</span> numpy_array_from_tuple <span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment"># <class 'numpy.ndarray'> </span>
<span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'numpy_array_from_tuple: '</span> <span class="token punctuation">,</span> numpy_array_from_tuple <span class="token punctuation">)</span> <span class="token comment"># numpy_array_from_tuple: [1 2 3 4 5]</span>
</code></pre> 
  <h2>24.12numpy 数组的形状</h2> 
  <p>shape 方法以元组的形式提供数组的形状。第一个是行,第二个是列。如果数组只是一维,则返回数组的大小。</p> 
  <pre><code class="prism language-python">   数字 <span class="token operator">=</span>  np。阵列(<span class="token punctuation">[</span> <span class="token number">1</span>,<span class="token number">2</span>,<span class="token number">3</span>,<span class="token number">4</span>,<span class="token number">5</span> <span class="token punctuation">]</span>)
    打印(NUMS)
    打印(<span class="token string">'NUMS的形状:'</span>,NUMS。形状)
    打印(numpy_two_dimensional_list)
    打印(<span class="token string">'numpy_two_dimensional_list的形状:'</span>,numpy_two_dimensional_list。形状)
     three_by_four_array  <span class="token operator">=</span>  NP。数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">,</span>
        <span class="token punctuation">[</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">,</span> <span class="token number">7</span> <span class="token punctuation">]</span><span class="token punctuation">,</span>
        <span class="token punctuation">[</span> <span class="token number">8</span>,<span class="token number">9</span>,<span class="token number">10</span>,<span class="token number">11</span> <span class="token punctuation">]</span><span class="token punctuation">]</span>)
    打印(three_by_four_array。形状)
</code></pre> 
  <pre><code class="prism language-python">   <span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span> <span class="token number">4</span> <span class="token number">5</span><span class="token punctuation">]</span>
    数字的形状:<span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token punctuation">)</span>
    <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">0</span> <span class="token number">1</span> <span class="token number">2</span><span class="token punctuation">]</span>
     <span class="token punctuation">[</span><span class="token number">3</span> <span class="token number">4</span> <span class="token number">5</span><span class="token punctuation">]</span>
     <span class="token punctuation">[</span><span class="token number">6</span> <span class="token number">7</span> <span class="token number">8</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
    numpy_two_dimensional_list 的形状:<span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span>
    <span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span>
</code></pre> 
  <h2>24.13numpy数组的数据类型</h2> 
  <p>数据类型类型:str、int、float、complex、bool、list、None</p> 
  <pre><code class="prism language-python">int_lists  <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token operator">-</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token operator">-</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token operator">-</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span>
 int_array  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 数组(int_lists)
 float_array  <span class="token operator">=</span>  np。阵列(int_lists,D型细胞<span class="token operator">=</span>浮动)

打印(INT_ARRAY)
打印(INT_ARRAY。D型细胞)
打印(float_array)
打印(float_array。D型)
</code></pre> 
  <p>[-3 -2 -1 0 1 2 3]<br> int64<br> [-3。-2. -1. 0. 1. 2. 3.]<br> 浮动64</p> 
  <h2>24.14numpy 数组的大小</h2> 
  <p>在 numpy 中要知道 numpy 数组列表中的项目数,我们使用 size</p> 
  <pre><code class="prism language-python">numpy_array_from_list  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
 two_dimensional_list  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">]</span><span class="token punctuation">,</span>
                              <span class="token punctuation">[</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">,</span>
                              <span class="token punctuation">[</span> <span class="token number">6</span> <span class="token punctuation">,</span> <span class="token number">7</span> <span class="token punctuation">,</span> <span class="token number">8</span> <span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>

<span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'The size:'</span> <span class="token punctuation">,</span> numpy_array_from_list <span class="token punctuation">.</span> size <span class="token punctuation">)</span> <span class="token comment"># 5 </span>
<span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'The size:'</span> <span class="token punctuation">,</span> two_dimensional_list <span class="token punctuation">.</span> size <span class="token punctuation">)</span>   <span class="token comment"># 3</span>
</code></pre> 
  <pre><code class="prism language-python">  尺寸:<span class="token number">5</span>
    尺寸:<span class="token number">9</span>
</code></pre> 
  <h2>24.15使用numpy进行数学运算</h2> 
  <p>NumPy 数组并不完全像 python 列表。要在 Python 列表中进行数学运算,我们必须遍历项目,但 numpy 可以允许在不循环的情况下进行任何数学运算。数学运算:</p> 
  <ol> 
   <li>加法 (+)</li> 
   <li>减法 (-)</li> 
   <li>乘法 (*)</li> 
   <li>分配 (/)</li> 
   <li>模块 (%)</li> 
   <li>楼层划分(//)</li> 
   <li>指数(**)</li> 
  </ol> 
  <h2>24.16添加</h2> 
  <pre><code class="prism language-python"><span class="token comment"># 数学运算</span>
<span class="token comment"># 加法</span>
numpy_array_from_list  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> <span class="token string">'原始数组: '</span> <span class="token punctuation">,</span> numpy_array_from_list <span class="token punctuation">)</span>
 ten_plus_original  <span class="token operator">=</span>  numpy_array_from_list   <span class="token operator">+</span>  <span class="token number">10</span>
打印<span class="token punctuation">(</span> ten_plus_original <span class="token punctuation">)</span>
</code></pre> 
  <p>原始数组:[1 2 3 4 5]<br> [11 12 13 14 15]</p> 
  <h2>24.17减法</h2> 
  <pre><code class="prism language-python"><span class="token comment"># 减法</span>
numpy_array_from_list  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> <span class="token string">'原始数组: '</span> <span class="token punctuation">,</span> numpy_array_from_list <span class="token punctuation">)</span>
 ten_minus_original  <span class="token operator">=</span>  numpy_array_from_list   <span class="token operator">-</span>  <span class="token number">10</span>
打印<span class="token punctuation">(</span> ten_minus_original <span class="token punctuation">)</span>
</code></pre> 
  <p>原始数组:[1 2 3 4 5]<br> [-9 -8 -7 -6 -5]</p> 
  <h2>24.18乘法</h2> 
  <pre><code class="prism language-python">numpy_array_from_list  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> <span class="token string">'原始数组: '</span> <span class="token punctuation">,</span> numpy_array_from_list <span class="token punctuation">)</span>
 ten_times_original  <span class="token operator">=</span>  numpy_array_from_list  <span class="token operator">*</span>  <span class="token number">10</span>
打印<span class="token punctuation">(</span> ten_times_original <span class="token punctuation">)</span>
</code></pre> 
  <p>原始数组:[1 2 3 4 5]<br> [10 20 30 40 50]</p> 
  <h2>24.19分配</h2> 
  <pre><code class="prism language-python"><span class="token comment"># 除法</span>
numpy_array_from_list  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> <span class="token string">'原始数组: '</span> <span class="token punctuation">,</span> numpy_array_from_list <span class="token punctuation">)</span>
 ten_times_original  <span class="token operator">=</span>  numpy_array_from_list  <span class="token operator">/</span>  <span class="token number">10</span>
打印<span class="token punctuation">(</span> ten_times_original <span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python"> 原始数组:<span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span> <span class="token number">4</span> <span class="token number">5</span><span class="token punctuation">]</span>
    <span class="token punctuation">[</span><span class="token number">0.1</span> <span class="token number">0.2</span> <span class="token number">0.3</span> <span class="token number">0.4</span> <span class="token number">0.5</span><span class="token punctuation">]</span>
</code></pre> 
  <h2>24.20模数;找到余数</h2> 
  <pre><code class="prism language-python">numpy_array_from_list  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> <span class="token string">'原始数组: '</span> <span class="token punctuation">,</span> numpy_array_from_list <span class="token punctuation">)</span>
 ten_times_original  <span class="token operator">=</span>  numpy_array_from_list  <span class="token operator">%</span>  <span class="token number">3</span>
打印<span class="token punctuation">(</span> ten_times_original <span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python">   原始数组:<span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span> <span class="token number">4</span> <span class="token number">5</span><span class="token punctuation">]</span>
    <span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">0</span> <span class="token number">1</span> <span class="token number">2</span><span class="token punctuation">]</span>
</code></pre> 
  <h2>24.21楼层划分</h2> 
  <pre><code class="prism language-python"><span class="token comment"># 楼层除法:没有余数的除法结果</span>
numpy_array_from_list  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> <span class="token string">'原始数组: '</span> <span class="token punctuation">,</span> numpy_array_from_list <span class="token punctuation">)</span>
 ten_times_original  <span class="token operator">=</span>  numpy_array_from_list  <span class="token operator">//</span>  <span class="token number">10</span>
打印<span class="token punctuation">(</span> ten_times_original <span class="token punctuation">)</span>
</code></pre> 
  <h2>24.22指数</h2> 
  <pre><code class="prism language-python"><span class="token comment"># Exponential 是找到某个数字的另一个幂:</span>
numpy_array_from_list  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> <span class="token string">'原始数组: '</span> <span class="token punctuation">,</span> numpy_array_from_list <span class="token punctuation">)</span>
 ten_times_original  <span class="token operator">=</span>  numpy_array_from_list   <span class="token operator">**</span>  <span class="token number">2</span>
打印<span class="token punctuation">(</span> ten_times_original <span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python">   原始数组:<span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span> <span class="token number">4</span> <span class="token number">5</span><span class="token punctuation">]</span>
    <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token number">4</span> <span class="token number">9</span> <span class="token number">16</span> <span class="token number">25</span><span class="token punctuation">]</span>
</code></pre> 
  <h2>24.23检查数据类型</h2> 
  <pre><code class="prism language-python"><span class="token comment">#Int, 浮点数</span>
numpy_int_arr  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
 numpy_float_arr  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1.1</span> <span class="token punctuation">,</span> <span class="token number">2.0</span> <span class="token punctuation">,</span> <span class="token number">3.2</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
 numpy_bool_arr  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token operator">-</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token operator">-</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> dtype <span class="token operator">=</span> <span class="token string">'bool'</span> <span class="token punctuation">)</span>

打印(numpy_int_arr。D型细胞)
打印(numpy_float_arr。D型细胞)
打印(numpy_bool_arr。D型)
</code></pre> 
  <pre><code class="prism language-python">int64
浮动<span class="token number">64</span>
布尔值
</code></pre> 
  <h2>24.24转换类型</h2> 
  <p>我们可以转换numpy数组的数据类型</p> 
  <p>1.整数到浮动</p> 
  <pre><code class="prism language-python">numpy_int_arr  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> dtype  <span class="token operator">=</span>  <span class="token string">'float'</span> <span class="token punctuation">)</span>
 numpy_int_arr
</code></pre> 
  <pre><code class="prism language-python">array<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <p>2.浮动到整数</p> 
  <pre><code class="prism language-python">numpy_int_arr  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span><span class="token punctuation">.</span> <span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span> <span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">.</span> <span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">.</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> dtype  <span class="token operator">=</span>  <span class="token string">'int'</span> <span class="token punctuation">)</span>
 numpy_int_arr
</code></pre> 
  <pre><code class="prism language-python">   数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <p>3.整数或布尔值</p> 
  <pre><code class="prism language-python">NP。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token operator">-</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token operator">-</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> dtype <span class="token operator">=</span> <span class="token string">'bool'</span> <span class="token punctuation">)</span>
</code></pre> 
  <p>数组([真,真,假,真,真,真])</p> 
  <p>4.整数到 str</p> 
  <pre><code class="prism language-python">numpy_float_list。astype <span class="token punctuation">(</span> <span class="token string">'int'</span> <span class="token punctuation">)</span>。astype(<span class="token string">'str'</span>)
</code></pre> 
  <p>数组([ ’ 1 ’ , ’ 2 ’ , ’ 3 ’ ], dtype= ’ <U21 ’ )</p> 
  <h2>24.25多维数组</h2> 
  <pre><code class="prism language-python"><span class="token comment"># 2 维数组</span>
two_dimension_array  <span class="token operator">=</span>  np <span class="token punctuation">.</span> array <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">(</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span> <span class="token number">7</span> <span class="token punctuation">,</span> <span class="token number">8</span> <span class="token punctuation">,</span> <span class="token number">9</span> <span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
 <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token builtin">type</span> <span class="token punctuation">(</span> two_dimension_array <span class="token punctuation">)</span><span class="token punctuation">)</span>
 <span class="token keyword">print</span> <span class="token punctuation">(</span> two_dimension_array <span class="token punctuation">)</span>
 <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'Shape: '</span> <span class="token punctuation">,</span> two_dimension_array <span class="token punctuation">.</span> shape <span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> <span class="token string">'大小:'</span>,two_dimension_array。尺寸)
的打印(<span class="token string">'数据类型:'</span>,two_dimension_array。D型)
</code></pre> 
  <p><类’ numpy.ndarray ’ ><br> [[1 2 3]<br> [4 5 6]<br> [7 8 9]]<br> 形状:(3, 3)<br> 尺寸:9<br> 数据类型:int64</p> 
  <h2>24.26从 numpy 数组中获取项目</h2> 
  <pre><code class="prism language-python"><span class="token comment"># 2 维数组</span>
two_dimension_array  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 阵列(<span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">1</span>,<span class="token number">2</span>,<span class="token number">3</span> <span class="token punctuation">]</span>,<span class="token punctuation">[</span> <span class="token number">4</span>,<span class="token number">5</span>,<span class="token number">6</span> <span class="token punctuation">]</span>,<span class="token punctuation">[</span> <span class="token number">7</span>,<span class="token number">8</span>,<span class="token number">9</span> <span class="token punctuation">]</span><span class="token punctuation">]</span>)
 FIRST_ROW  <span class="token operator">=</span>  two_dimension_array <span class="token punctuation">[</span> <span class="token number">0</span> <span class="token punctuation">]</span>
 second_row  <span class="token operator">=</span>  two_dimension_array <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">]</span>
 third_row  <span class="token operator">=</span>  two_dimension_array <span class="token punctuation">[</span> <span class="token number">2</span> <span class="token punctuation">]</span>
打印(“第一行:' <span class="token punctuation">,</span> first_row <span class="token punctuation">)</span>
打印(<span class="token string">'第二行:'</span>,second_row)
打印(<span class="token string">'第三行:'</span>,third_row)
</code></pre> 
  <p>第一行:[1 2 3]<br> 第二行:[4 5 6]<br> 第三行:[7 8 9]</p> 
  <pre><code class="prism language-python">first_column <span class="token operator">=</span>  two_dimension_array <span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token punctuation">,</span> <span class="token number">0</span> <span class="token punctuation">]</span>
 second_column  <span class="token operator">=</span>  two_dimension_array <span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">]</span>
 third_column  <span class="token operator">=</span>  two_dimension_array <span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">]</span>
 <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'First column:'</span> <span class="token punctuation">,</span> first_column <span class="token punctuation">)</span>
 <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'Second column:'</span> <span class="token punctuation">,</span> second_column <span class="token punctuation">)</span>
 <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'第三列: '</span> <span class="token punctuation">,</span> third_column <span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> two_dimension_array <span class="token punctuation">)</span>
</code></pre> 
  <p>第一列:[1 4 7]<br> 第二列:[2 5 8]<br> 第三列:[3 6 9]<br> [[1 2 3]<br> [4 5 6]<br> [7 8 9]]</p> 
  <h2>24.27切片 Numpy 数组</h2> 
  <p>在 numpy 中切片类似于在 python list 中切片</p> 
  <pre><code class="prism language-python">two_dimension_array  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token punctuation">[</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span> <span class="token number">7</span> <span class="token punctuation">,</span> <span class="token number">8</span> <span class="token punctuation">,</span> <span class="token number">9</span> <span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
 first_two_rows_and_columns  <span class="token operator">=</span>  two_dimension_array <span class="token punctuation">[</span> <span class="token number">0</span> <span class="token punctuation">:</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">0</span> <span class="token punctuation">:</span> <span class="token number">2</span> <span class="token punctuation">]</span>
打印<span class="token punctuation">(</span> first_two_rows_and_columns <span class="token punctuation">)</span>
</code></pre> 
  <p>[[1 2]<br> [4 5]]</p> 
  <h2>24.28如何反转行和整个数组?</h2> 
  <pre><code class="prism language-python">二维数组<span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token punctuation">]</span>
</code></pre> 
  <p>数组([[1, 2, 3],<br> [4, 5, 6],<br> [7, 8, 9]])</p> 
  <h2>24.29反转行列位置</h2> 
  <pre><code class="prism language-python">two_dimension_array  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token punctuation">[</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span> <span class="token number">7</span> <span class="token punctuation">,</span> <span class="token number">8</span> <span class="token punctuation">,</span> <span class="token number">9</span> <span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
 two_dimension_array <span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token punctuation">:</span> <span class="token operator">-</span> <span class="token number">1</span> <span class="token punctuation">,</span><span class="token punctuation">:</span><span class="token punctuation">:</span> <span class="token operator">-</span> <span class="token number">1</span> <span class="token punctuation">]</span>
</code></pre> 
  <p>数组([[9, 8, 7],<br> [6, 5, 4],<br> [3, 2, 1]])</p> 
  <h2>24.30如何表示缺失值?</h2> 
  <pre><code class="prism language-python">打印<span class="token punctuation">(</span> two_dimension_array <span class="token punctuation">)</span>
 two_dimension_array <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  <span class="token number">55</span> 
two_dimension_array <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">44</span>
打印<span class="token punctuation">(</span> two_dimension_array <span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python"><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span><span class="token punctuation">]</span>
 <span class="token punctuation">[</span><span class="token number">4</span> <span class="token number">5</span> <span class="token number">6</span><span class="token punctuation">]</span>
 <span class="token punctuation">[</span><span class="token number">7</span> <span class="token number">8</span> <span class="token number">9</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span><span class="token punctuation">]</span>
 <span class="token punctuation">[</span> <span class="token number">4</span> <span class="token number">55</span> <span class="token number">44</span><span class="token punctuation">]</span>
 <span class="token punctuation">[</span> <span class="token number">7</span> <span class="token number">8</span> <span class="token number">9</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
</code></pre> 
  <pre><code class="prism language-python"> <span class="token comment"># Numpy </span>
    Zeroes <span class="token comment"># numpy.zeros(shape, dtype=float, order='C') </span>
    numpy_zeroes  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 零<span class="token punctuation">(</span><span class="token punctuation">(</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">)</span><span class="token punctuation">,</span> dtype <span class="token operator">=</span> <span class="token builtin">int</span> <span class="token punctuation">,</span> order <span class="token operator">=</span> <span class="token string">'C'</span> <span class="token punctuation">)</span>
     numpy_zeroes
</code></pre> 
  <pre><code class="prism language-python">数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python"><span class="token comment"># Numpy</span>
归零 numpy_ones  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 个<span class="token punctuation">(</span><span class="token punctuation">(</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">)</span><span class="token punctuation">,</span> dtype <span class="token operator">=</span> <span class="token builtin">int</span> <span class="token punctuation">,</span> order <span class="token operator">=</span> <span class="token string">'C'</span> <span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> numpy_ones <span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python"><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">1</span> <span class="token number">1</span><span class="token punctuation">]</span>
 <span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">1</span> <span class="token number">1</span><span class="token punctuation">]</span>
 <span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">1</span> <span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
</code></pre> 
  <pre><code class="prism language-python">两个 <span class="token operator">=</span>  numpy_ones  <span class="token operator">*</span>  <span class="token number">2</span>
</code></pre> 
  <pre><code class="prism language-python"><span class="token comment"># 重塑</span>
<span class="token comment"># numpy.reshape(), numpy.flatten() </span>
first_shape   <span class="token operator">=</span>  np <span class="token punctuation">.</span> 阵列(<span class="token punctuation">[</span>(<span class="token number">1</span>,<span class="token number">2</span>,<span class="token number">3</span>),(<span class="token number">4</span>,<span class="token number">5</span>,<span class="token number">6</span>)<span class="token punctuation">]</span>)
打印(first_shape)
重构 <span class="token operator">=</span>  first_shape。重塑(<span class="token number">3</span>,<span class="token number">2</span>)
打印(重塑)
    <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span><span class="token punctuation">]</span>
     <span class="token punctuation">[</span><span class="token number">4</span> <span class="token number">5</span> <span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
    <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span><span class="token punctuation">]</span>
     <span class="token punctuation">[</span><span class="token number">3</span> <span class="token number">4</span><span class="token punctuation">]</span>
     <span class="token punctuation">[</span><span class="token number">5</span> <span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
</code></pre> 
  <pre><code class="prism language-python">扁平 <span class="token operator">=</span> 重塑。flatten <span class="token punctuation">(</span><span class="token punctuation">)</span>
扁平化
</code></pre> 
  <pre><code class="prism language-python">数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token comment">## 水平堆栈</span>
np_list_one  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
 np_list_two  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>

打印(np_list_one  <span class="token operator">+</span>  np_list_two)

打印(<span class="token string">'水平附加:'</span>,NP。hstack((np_list_one,np_list_two)))
<span class="token punctuation">[</span><span class="token number">5</span> <span class="token number">7</span> <span class="token number">9</span><span class="token punctuation">]</span>
水平追加:<span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span> <span class="token number">4</span> <span class="token number">5</span> <span class="token number">6</span><span class="token punctuation">]</span>
</code></pre> 
  <p>##垂直叠<br> 打印(‘垂直附加:’,NP。vstack((np_list_one,np_list_two)))<br> 垂直附加:[[1 2 3]<br> [4 5 6]]</p> 
  <h2>24.31生成随机数</h2> 
  <pre><code class="prism language-python">  <span class="token comment"># 生成一个随机浮点数</span>
    random_float  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 随机的。随机()
     random_float
    <span class="token number">0.018929887384753874</span>
    <span class="token comment"># 生成一个随机浮点数</span>
    random_floats  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 随机的。随机<span class="token punctuation">(</span> <span class="token number">5</span> <span class="token punctuation">)</span>
     random_floats
    数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">0.26392192</span><span class="token punctuation">,</span> <span class="token number">0.35842215</span><span class="token punctuation">,</span> <span class="token number">0.87908478</span><span class="token punctuation">,</span> <span class="token number">0.41902195</span><span class="token punctuation">,</span> <span class="token number">0.78926418</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
    <span class="token comment"># 生成 0 到 10 之间的随机整数</span>

    random_int  <span class="token operator">=</span>  np。随机的。randint <span class="token punctuation">(</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">11</span> <span class="token punctuation">)</span>
     random_int
    <span class="token number">4</span>
    <span class="token comment"># 生成一个 2 到 11 之间的随机整数,并创建一个</span>
    单行 数组random_int <span class="token operator">=</span>  np <span class="token punctuation">.</span> 随机的。randint <span class="token punctuation">(</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">10</span> <span class="token punctuation">,</span> size <span class="token operator">=</span> <span class="token number">4</span> <span class="token punctuation">)</span>
     random_int
    数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
    <span class="token comment"># 生成 0 到 10 之间的随机整数</span>
    random_int  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 随机的。randint <span class="token punctuation">(</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">10</span> <span class="token punctuation">,</span> size <span class="token operator">=</span> <span class="token punctuation">(</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">)</span><span class="token punctuation">)</span>
     random_int
    数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
           <span class="token punctuation">[</span><span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
           <span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <h2>24.32生成随机数</h2> 
  <pre><code class="prism language-python"> <span class="token comment"># np.random.normal(mu, sigma, size) </span>
    normal_array  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 随机的。正常<span class="token punctuation">(</span> <span class="token number">79</span> <span class="token punctuation">,</span> <span class="token number">15</span> <span class="token punctuation">,</span> <span class="token number">80</span> <span class="token punctuation">)</span>
     normal_array
</code></pre> 
  <pre><code class="prism language-python"> 数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">89.49990595</span><span class="token punctuation">,</span> <span class="token number">82.06056961</span><span class="token punctuation">,</span> <span class="token number">107.21445842</span><span class="token punctuation">,</span> <span class="token number">38.69307086</span><span class="token punctuation">,</span>
            <span class="token number">47.85259157</span>、<span class="token number">93.07381061</span>、<span class="token number">76.40724259</span>、<span class="token number">78.55675184</span>、
            <span class="token number">72.17358173</span>、<span class="token number">47.9888899</span>、<span class="token number">65.10370622</span>、<span class="token number">76.29696568</span>、
            <span class="token number">95.58234254</span>、<span class="token number">68.14897213</span>、<span class="token number">38.75862686</span>、<span class="token number">122.5587927</span>、
            <span class="token number">67.0762565</span>、<span class="token number">95.73990864</span>、<span class="token number">81.97454563</span>、<span class="token number">92.54264805</span>、
            <span class="token number">59.37035153</span>、<span class="token number">77.76828101</span>、<span class="token number">52.30752166</span>、<span class="token number">64.43109931</span>、
            <span class="token number">62.63695351</span>、<span class="token number">90.04616138</span>、<span class="token number">75.70009094</span>、<span class="token number">49.87586877</span>、
            <span class="token number">80.22002414</span>、<span class="token number">68.56708848</span>、<span class="token number">76.27791052</span>、<span class="token number">67.24343975</span>、
            <span class="token number">81.86363935</span>、<span class="token number">78.22703433</span>、<span class="token number">102.85737041</span>、<span class="token number">65.15700341</span>、
            <span class="token number">84.87033426</span>、<span class="token number">76.7569997</span>、<span class="token number">64.61321853</span>、<span class="token number">67.37244562</span>、
            <span class="token number">74.4068773</span>、<span class="token number">58.65119655</span>、<span class="token number">71.66488727</span>、<span class="token number">53.42458179</span>、
            <span class="token number">70.26872028</span>、<span class="token number">60.96588544</span>、<span class="token number">83.56129414</span>、<span class="token number">72.14255326</span>、
            <span class="token number">81.00787609</span>、<span class="token number">71.81264853</span>、<span class="token number">72.64168853</span>、<span class="token number">86.56608717</span>、
            <span class="token number">94.94667321</span>、<span class="token number">82.32676973</span>、<span class="token number">70.5165446</span>、<span class="token number">85.43061003</span>、
            <span class="token number">72.45526212</span>、<span class="token number">87.34681775</span>、<span class="token number">87.69911217</span>、<span class="token number">103.02831489</span>、
            <span class="token number">75.28598596</span>、<span class="token number">67.17806893</span>、<span class="token number">92.41274447</span>、<span class="token number">101.06662611</span>、
            <span class="token number">87.70013935</span>、<span class="token number">70.73980645</span>、<span class="token number">46.40368207</span>、<span class="token number">50.17947092</span>、
            <span class="token number">61.75618542</span>、<span class="token number">90.26191397</span>、<span class="token number">78.63968639</span>、<span class="token number">70.84550744</span>、
            <span class="token number">88.91826581</span>、<span class="token number">103.91474733</span>、<span class="token number">66.3064638</span>、<span class="token number">79.49726264</span>、
            <span class="token number">70.81087439</span><span class="token punctuation">,</span> <span class="token number">83.90130623</span><span class="token punctuation">,</span> <span class="token number">87.58555972</span><span class="token punctuation">,</span> <span class="token number">59.95462521</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <h2>24.33Numpy 和统计</h2> 
  <pre><code class="prism language-python">导入 matplotlib。pyplot  <span class="token keyword">as</span>  plt
将 seaborn 作为 sns 
sns导入。设置<span class="token punctuation">(</span><span class="token punctuation">)</span>
 plt。hist <span class="token punctuation">(</span> normal_array <span class="token punctuation">,</span> color <span class="token operator">=</span> <span class="token string">"grey"</span> <span class="token punctuation">,</span> bins <span class="token operator">=</span> <span class="token number">50</span> <span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python"> <span class="token punctuation">(</span>数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">.</span><span class="token punctuation">,</span>
            <span class="token number">4</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span> <span class="token punctuation">,</span>
            <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
     数组(<span class="token punctuation">[</span> <span class="token number">38.69307086</span><span class="token punctuation">,</span> <span class="token number">40.37038529</span><span class="token punctuation">,</span> <span class="token number">42.04769973</span><span class="token punctuation">,</span> <span class="token number">43.72501417</span><span class="token punctuation">,</span>
             <span class="token number">45.4023286</span>、<span class="token number">47.07964304</span>、<span class="token number">48.75695748</span>、<span class="token number">50.43427191</span>、
             <span class="token number">52.11158635</span>、<span class="token number">53.78890079</span>、<span class="token number">55.46621523</span>、<span class="token number">57.14352966</span>、
             <span class="token number">58.8208441</span>、<span class="token number">60.49815854</span>、<span class="token number">62.17547297</span>、<span class="token number">63.85278741</span>、
             <span class="token number">65.53010185</span>、<span class="token number">67.20741628</span>、<span class="token number">68.88473072</span>、<span class="token number">70.56204516</span>、
             <span class="token number">72.23935959</span>、<span class="token number">73.91667403</span>、<span class="token number">75.59398847</span>、<span class="token number">77.27130291</span>、
             <span class="token number">78.94861734</span>、<span class="token number">80.62593178</span>、<span class="token number">82.30324622</span>、<span class="token number">83.98056065</span>、
             <span class="token number">85.65787509</span>、<span class="token number">87.33518953</span>、<span class="token number">89.01250396</span>、<span class="token number">90.6898184</span>、
             <span class="token number">92.36713284</span>、<span class="token number">94.04444727</span>、<span class="token number">95.72176171</span>、<span class="token number">97.39907615</span>、
             <span class="token number">99.07639058</span>、<span class="token number">100.75370502</span>、<span class="token number">102.43101946</span>、<span class="token number">104.1083339</span>、
            <span class="token number">105.78564833</span>、<span class="token number">107.46296277</span>、<span class="token number">109.14027721</span>、<span class="token number">110.81759164</span>、
            <span class="token number">112.49490608</span>、<span class="token number">114.17222052</span>、<span class="token number">115.84953495</span>、<span class="token number">117.52684939</span>、
            <span class="token number">119.20416383</span><span class="token punctuation">,</span> <span class="token number">120.88147826</span><span class="token punctuation">,</span> <span class="token number">122.5587927</span> <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
     <span class="token operator"><</span> <span class="token number">50</span> 个 Patch 对象的列表<span class="token operator">></span> <span class="token punctuation">)</span>
</code></pre> 
  <h2>24.34numpy中的矩阵</h2> 
  <pre><code class="prism language-python">Four_by_four_matrix  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 矩阵(NP。者((<span class="token number">4</span>,<span class="token number">4</span>),D型细胞<span class="token operator">=</span>浮动))
Four_by_four_matrix
矩阵<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
NP。asarray(four_by_four_matrix)<span class="token punctuation">[</span> <span class="token number">2</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  <span class="token number">2</span>个
four_by_four_matrix
矩阵<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <h2>24.35numpy numpy.arange()</h2> 
  <p>有时,您希望创建在定义的间隔内均匀分布的值。例如,您想创建从 1 到 10 的值;你可以使用 numpy.arange() 函数</p> 
  <pre><code class="prism language-python"><span class="token comment"># 使用 range(starting, stop, step) 创建列表</span>
lst  <span class="token operator">=</span>  <span class="token builtin">range</span> <span class="token punctuation">(</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">11</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">)</span>
 lst
范围<span class="token punctuation">(</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">11</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">)</span>
<span class="token keyword">for</span>  l  <span class="token keyword">in</span>  lst <span class="token punctuation">:</span>
    打印<span class="token punctuation">(</span> l <span class="token punctuation">)</span>
    <span class="token number">2</span>
    <span class="token number">4</span>
    <span class="token number">6</span>
    <span class="token number">8</span>
    <span class="token number">10</span>
</code></pre> 
  <pre><code class="prism language-python"><span class="token comment"># 类似于范围 arange numpy.arange(start, stop, step) </span>
whole_numbers  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 范围<span class="token punctuation">(</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">20</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">)</span>
整数
数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">,</span> <span class="token number">13</span><span class="token punctuation">,</span> <span class="token number">14</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">,</span>
           <span class="token number">17</span><span class="token punctuation">,</span> <span class="token number">18</span><span class="token punctuation">,</span> <span class="token number">19</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
natural_numbers  <span class="token operator">=</span>  np。arange <span class="token punctuation">(</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">20</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">)</span>
 natural_numbers
奇数 <span class="token operator">=</span>  np。arange <span class="token punctuation">(</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">20</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">)</span>
奇数
    数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">,</span> <span class="token number">13</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">17</span><span class="token punctuation">,</span> <span class="token number">19</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
even_numbers  <span class="token operator">=</span>  np。arange <span class="token punctuation">(</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">20</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">)</span>
 even_numbers
    数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">,</span> <span class="token number">14</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">,</span> <span class="token number">18</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <h2>24.36使用 linspace 创建数字序列</h2> 
  <pre><code class="prism language-python"><span class="token comment"># numpy.linspace() </span>
<span class="token comment"># numpy.logspace() in Python with Example </span>
<span class="token comment"># 例如,它可以用来创建从 1 到 5 的 10 个均匀间隔的值。</span>
NP。linspace <span class="token punctuation">(</span> <span class="token number">1.0</span> <span class="token punctuation">,</span> <span class="token number">5.0</span> <span class="token punctuation">,</span> num <span class="token operator">=</span> <span class="token number">10</span> <span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python">    数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1.44444444</span><span class="token punctuation">,</span> <span class="token number">1.88888889</span><span class="token punctuation">,</span> <span class="token number">2.33333333</span><span class="token punctuation">,</span> <span class="token number">2.77777778</span><span class="token punctuation">,</span>
           <span class="token number">3.22222222</span><span class="token punctuation">,</span> <span class="token number">3.66666667</span><span class="token punctuation">,</span> <span class="token number">4.11111111</span><span class="token punctuation">,</span> <span class="token number">4.55555556</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token comment"># 不包括区间</span>
np 中的最后一个值。linspace <span class="token punctuation">(</span> <span class="token number">1.0</span> <span class="token punctuation">,</span> <span class="token number">5.0</span> <span class="token punctuation">,</span> num <span class="token operator">=</span> <span class="token number">5</span> <span class="token punctuation">,</span>端点<span class="token operator">=</span> <span class="token boolean">False</span> <span class="token punctuation">)</span>
array<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span> <span class="token punctuation">,</span> <span class="token number">1.8</span><span class="token punctuation">,</span> <span class="token number">2.6</span><span class="token punctuation">,</span> <span class="token number">3.4</span><span class="token punctuation">,</span> <span class="token number">4.2</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python"><span class="token comment"># LogSpace </span>
<span class="token comment"># LogSpace 返回对数刻度上的偶数间隔数。Logspace 具有与 np.linspace 相同的参数。</span>

# 句法:

<span class="token comment"># numpy.logspace(开始,停止,数量,端点)</span>

NP。日志空间<span class="token punctuation">(</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">4.0</span> <span class="token punctuation">,</span> num <span class="token operator">=</span> <span class="token number">4</span> <span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python">数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">100</span><span class="token punctuation">.</span> <span class="token punctuation">,</span> <span class="token number">464.15888336</span><span class="token punctuation">,</span> <span class="token number">2154.43469003</span><span class="token punctuation">,</span> <span class="token number">10000</span><span class="token punctuation">.</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token comment"># 检查数组的大小</span>
x  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 阵列(<span class="token punctuation">[</span> <span class="token number">1</span>,<span class="token number">2</span>,<span class="token number">3</span> <span class="token punctuation">]</span>,D型细胞<span class="token operator">=</span> NP。complex128)
X
    数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token operator">+</span><span class="token number">0.j</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">.</span><span class="token operator">+</span><span class="token number">0.j</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">.</span><span class="token operator">+</span><span class="token number">0.j</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
×。项目大小
<span class="token number">16</span>
<span class="token comment"># 在 Python 中索引和切片 NumPy 数组</span>
np_list  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">(</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
 np_list
    数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
           <span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
打印(<span class="token string">'第一行:'</span>,np_list <span class="token punctuation">[</span> <span class="token number">0</span> <span class="token punctuation">]</span>)
打印(<span class="token string">'第二行:'</span>,np_list <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">]</span>)
    第一行:<span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span><span class="token punctuation">]</span>
    第二行:<span class="token punctuation">[</span><span class="token number">4</span> <span class="token number">5</span> <span class="token number">6</span><span class="token punctuation">]</span>
打印(<span class="token string">'第一列:'</span>,np_list<span class="token punctuation">[</span> :,<span class="token number">0</span> <span class="token punctuation">]</span>)
打印(<span class="token string">'第二列:'</span>,np_list<span class="token punctuation">[</span> :,<span class="token number">1</span> <span class="token punctuation">]</span>)
打印(<span class="token string">'第三列:'</span>,np_list<span class="token punctuation">[</span> :,<span class="token number">2</span> <span class="token punctuation">]</span>)
    第一列:<span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">4</span><span class="token punctuation">]</span>
    第二列:<span class="token punctuation">[</span><span class="token number">2</span> <span class="token number">5</span><span class="token punctuation">]</span>
    第三列:<span class="token punctuation">[</span><span class="token number">3</span> <span class="token number">6</span><span class="token punctuation">]</span>
</code></pre> 
  <h2>24.37NumPy 统计函数与示例</h2> 
  <p>NumPy 具有非常有用的统计函数,用于从数组中的给定元素中查找最小值、最大值、平均值、中位数、百分位数、标准偏差和方差等。函数解释如下 - 统计函数 Numpy 配备了如下所列的稳健统计函数</p> 
  <ul> 
   <li>Numpy 函数</li> 
  </ul> 
  <ul> 
   <li>最小 np.min()</li> 
   <li>最大 np.max()</li> 
   <li>平均 np.mean()</li> 
   <li>中位数 np.median()</li> 
   <li>差异</li> 
   <li>百分位</li> 
   <li>标准差 np.std()</li> 
  </ul> 
  <pre><code class="prism language-python">np_normal_dis  <span class="token operator">=</span>  np。随机的。正常(<span class="token number">5</span>,<span class="token number">0.5</span>,<span class="token number">100</span>)
 np_normal_dis 
<span class="token comment">##最小值,最大值,平均值,中位数,SD</span>
打印(<span class="token string">'分钟:'</span>,two_dimension_array。分钟())
的打印(<span class="token string">'最大:'</span>,two_dimension_array。最大())
的打印(“平均: ' two_dimension_array。意思是())
#打印('中位数”,two_dimension_array<span class="token punctuation">.</span>median())
打印(<span class="token string">'SD:'</span><span class="token punctuation">,</span> two_dimension_array。标准<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python"><span class="token builtin">min</span><span class="token punctuation">:</span>  <span class="token number">1</span>
<span class="token builtin">max</span><span class="token punctuation">:</span>  <span class="token number">55</span>
mean<span class="token punctuation">:</span>  <span class="token number">14.777777777777779</span>
sd<span class="token punctuation">:</span>  <span class="token number">18.913709183069525</span>
最小值:   <span class="token number">1</span>
最大值:   <span class="token number">55</span>
平均值:   <span class="token number">14.777777777777779</span> 标准
差:   <span class="token number">18.913709183069525</span>
</code></pre> 
  <pre><code class="prism language-python">打印(two_dimension_array)
打印(<span class="token string">'列具有最小:'</span>,NP。阿明(two_dimension_array,轴<span class="token operator">=</span> <span class="token number">0</span>))
的打印(<span class="token string">'列具有最大:'</span>,NP。AMAX(two_dimension_array,轴<span class="token operator">=</span> <span class="token number">0</span>))
的打印(“<span class="token operator">==</span><span class="token operator">=</span>行<span class="token operator">==</span>”)
打印(<span class="token string">'行用最小的:'</span>,NP。阿明(two_dimension_array,轴<span class="token operator">=</span> <span class="token number">1</span>))
的打印(<span class="token string">'行用最大:'</span>,NP。AMAX(two_dimension_array,轴<span class="token operator">=</span> <span class="token number">1</span>))


<span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">1</span>  <span class="token number">2</span>  <span class="token number">3</span><span class="token punctuation">]</span>
 <span class="token punctuation">[</span> <span class="token number">4</span> <span class="token number">55</span> <span class="token number">44</span><span class="token punctuation">]</span>
 <span class="token punctuation">[</span> <span class="token number">7</span>  <span class="token number">8</span>  <span class="token number">9</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
Column <span class="token keyword">with</span> minimum<span class="token punctuation">:</span>  <span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span><span class="token punctuation">]</span>
Column <span class="token keyword">with</span> maximum<span class="token punctuation">:</span>  <span class="token punctuation">[</span> <span class="token number">7</span> <span class="token number">55</span> <span class="token number">44</span><span class="token punctuation">]</span>
<span class="token operator">==</span><span class="token operator">=</span> Row <span class="token operator">==</span>
Row <span class="token keyword">with</span> minimum<span class="token punctuation">:</span>  <span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">4</span> <span class="token number">7</span><span class="token punctuation">]</span>
Row <span class="token keyword">with</span> maximum<span class="token punctuation">:</span>  <span class="token punctuation">[</span> <span class="token number">3</span> <span class="token number">55</span>  <span class="token number">9</span><span class="token punctuation">]</span>
</code></pre> 
  <h2>24.38如何创建重复序列?</h2> 
  <pre><code class="prism language-python">a  <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span>

#整个重复的<span class="token string">'A'</span>两次
打印(<span class="token string">'平铺:'</span>,NP。瓷砖(一,<span class="token number">2</span>))

#重复的<span class="token string">'A'</span>两次各元件
打印(<span class="token string">'重复:'</span>,NP。重复(一,<span class="token number">2</span>))
Tile<span class="token punctuation">:</span>    <span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span> <span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span><span class="token punctuation">]</span>
Repeat<span class="token punctuation">:</span>  <span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">1</span> <span class="token number">2</span> <span class="token number">2</span> <span class="token number">3</span> <span class="token number">3</span><span class="token punctuation">]</span>
</code></pre> 
  <h2>24.39如何生成随机数?</h2> 
  <pre><code class="prism language-python"><span class="token comment"># [0,1) </span>
one_random_num  <span class="token operator">=</span>  np之间的一个随机数。随机的。随机<span class="token punctuation">(</span><span class="token punctuation">)</span>
 one_random_in  <span class="token operator">=</span>  np。随机
打印(one_random_num)
<span class="token number">0.6149403282678213</span>
<span class="token number">0.4763968133790438</span>
<span class="token number">0.4763968133790438</span>
<span class="token comment"># 形状为 2,3 的 [0,1) 之间的随机数</span>
r  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 随机的。随机<span class="token punctuation">(</span> size <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> r <span class="token punctuation">)</span>
<span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">0.13031737</span> <span class="token number">0.4429537</span>  <span class="token number">0.1129527</span> <span class="token punctuation">]</span>
 <span class="token punctuation">[</span><span class="token number">0.76811539</span> <span class="token number">0.88256594</span> <span class="token number">0.6754075</span> <span class="token punctuation">]</span><span class="token punctuation">]</span>
打印<span class="token punctuation">(</span> np <span class="token punctuation">.</span> random <span class="token punctuation">.</span> choice <span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token string">'a'</span> <span class="token punctuation">,</span> <span class="token string">'e'</span> <span class="token punctuation">,</span> <span class="token string">'i'</span> <span class="token punctuation">,</span> <span class="token string">'o'</span> <span class="token punctuation">,</span> <span class="token string">'u'</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> size <span class="token operator">=</span> <span class="token number">10</span> <span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">[</span><span class="token string">'u'</span> <span class="token string">'o'</span> <span class="token string">'o'</span> <span class="token string">'i'</span> <span class="token string">'e'</span> <span class="token string">'e'</span> <span class="token string">'u'</span> <span class="token string">'o'</span> <span class="token string">'u'</span> <span class="token string">'a'</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span> <span class="token string">'i'</span>  <span class="token string">'u'</span>  <span class="token string">'e'</span>  <span class="token string">'o'</span>  <span class="token string">'a'</span>  <span class="token string">'i'</span>  <span class="token string">'e'</span>  <span class="token string">'u'</span>  <span class="token string">'o'</span>  <span class="token string">'i'</span> <span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token string">'iueoaieuoi'</span><span class="token punctuation">]</span>
<span class="token comment">## 形状 2, 2 的 [0, 1] 之间的随机数</span>
rand  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 随机的。兰特<span class="token punctuation">(</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">)</span>
兰特
array<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">0.97992598</span><span class="token punctuation">,</span> <span class="token number">0.79642484</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">0.65263629</span><span class="token punctuation">,</span> <span class="token number">0.55763145</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
rand2  <span class="token operator">=</span>  np。随机的。randn <span class="token punctuation">(</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">)</span>
 rand2
array<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">1.65593322</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">0.52326621</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span> <span class="token number">0.39071179</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">2.03649407</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token comment"># 形状为 2,5 的 [0, 10) 之间的随机整数</span>
rand_int  <span class="token operator">=</span>  np <span class="token punctuation">.</span> 随机的。randint <span class="token punctuation">(</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">10</span> <span class="token punctuation">,</span> size <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
 rand_int
array<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <pre><code class="prism language-python">从 scipy 导入 统计
np_normal_dis  <span class="token operator">=</span>  np。随机的。正常(<span class="token number">5</span>,<span class="token number">0.5</span>,<span class="token number">1000</span>)#平均值,标准偏差,样本数
np_normal_dis 
<span class="token comment">##最小值,最大值,平均值,中位数,SD</span>
打印(<span class="token string">'分钟:'</span>,NP。分钟(np_normal_dis))
打印(<span class="token string">'最大:'</span>,np <span class="token punctuation">.</span> <span class="token builtin">max</span> <span class="token punctuation">(</span> np_normal_dis <span class="token punctuation">)</span><span class="token punctuation">)</span>
 <span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'mean: '</span> <span class="token punctuation">,</span> np <span class="token punctuation">.</span>均值(np_normal_dis))
打印(<span class="token string">'中位数:'</span>,NP。中值(np_normal_dis))
打印(<span class="token string">'模式:'</span>,统计信息。模式(np_normal_dis))
打印(<span class="token string">'SD:'</span>,NP。STD(np_normal_dis))
    分钟:<span class="token number">3.557811005458804</span>
    最大:<span class="token number">6.876317743643499</span>
    平均值:<span class="token number">5.035832048106663</span>
    中位数:<span class="token number">5.020161980441937</span>
    模式:模式结果(模式<span class="token operator">=</span>数组(<span class="token punctuation">[</span><span class="token number">3.55781101</span><span class="token punctuation">]</span>),计数<span class="token operator">=</span>数组(<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>))
    标准差:<span class="token number">0.489682424165213</span>
PLT。hist <span class="token punctuation">(</span> np_normal_dis <span class="token punctuation">,</span> color <span class="token operator">=</span> <span class="token string">"grey"</span> <span class="token punctuation">,</span> bins <span class="token operator">=</span> <span class="token number">21</span> <span class="token punctuation">)</span>
 plt。显示<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/c9fbd233a88643dbb62d85f2f7d57c73.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/c9fbd233a88643dbb62d85f2f7d57c73.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第2张图片" width="388" height="264" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-python"><span class="token comment"># numpy.dot(): Python 中使用 Numpy 的</span>
Dot Product 
<span class="token comment"># Dot Product # Numpy 是强大的矩阵计算库。例如,您可以使用 np.dot 计算点积</span>

# 句法

<span class="token comment"># numpy.dot(x, y, out=None)</span>
</code></pre> 
  <h2>24.40线性代数</h2> 
  <p>点积</p> 
  <pre><code class="prism language-python"><span class="token comment">## 线性代数</span>
<span class="token comment">### 点积:两个数组的乘积</span>
f  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
 g  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
 <span class="token comment">### 1*4+2*5 + 3*6 </span>
np <span class="token punctuation">.</span> 点<span class="token punctuation">(</span> f <span class="token punctuation">,</span> g <span class="token punctuation">)</span>   <span class="token comment"># 23</span>
</code></pre> 
  <h2>24.41NumPy 矩阵乘法与 np.matmul()</h2> 
  <pre><code class="prism language-python"><span class="token comment">### Matmul:两个数组的矩阵乘积</span>
h  <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token punctuation">[</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">]</span><span class="token punctuation">]</span>
 i  <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token punctuation">[</span> <span class="token number">7</span> <span class="token punctuation">,</span> <span class="token number">8</span> <span class="token punctuation">]</span><span class="token punctuation">]</span>
 <span class="token comment">### 1*5+2*7 = 19</span>
纳米。matmul <span class="token punctuation">(</span> h <span class="token punctuation">,</span> i <span class="token punctuation">)</span>
    数组<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">19</span><span class="token punctuation">,</span> <span class="token number">22</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
           <span class="token punctuation">[</span><span class="token number">43</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token comment">##行列式2*2矩阵</span>
<span class="token comment">###5*8-7*6np.linalg.det(i)</span>
NP。linalg。检测<span class="token punctuation">(</span> i <span class="token punctuation">)</span>
<span class="token operator">-</span><span class="token number">1.999999999999999</span>
Z  <span class="token operator">=</span>  np。零<span class="token punctuation">(</span><span class="token punctuation">(</span> <span class="token number">8</span> <span class="token punctuation">,</span> <span class="token number">8</span> <span class="token punctuation">)</span><span class="token punctuation">)</span>
 Z <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">:</span><span class="token punctuation">:</span> <span class="token number">2</span> <span class="token punctuation">,</span><span class="token punctuation">:</span><span class="token punctuation">:</span> <span class="token number">2</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  <span class="token number">1</span> 
Z <span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token punctuation">:</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">:</span><span class="token punctuation">:</span> <span class="token number">2</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  <span class="token number">1</span>
Z
</code></pre> 
  <pre><code class="prism language-python">array<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
       <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
new_list  <span class="token operator">=</span> <span class="token punctuation">[</span> x  <span class="token operator">+</span>  <span class="token number">2</span>  <span class="token keyword">for</span>  x  <span class="token keyword">in</span>  <span class="token builtin">range</span> <span class="token punctuation">(</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">11</span> <span class="token punctuation">)</span><span class="token punctuation">]</span>
</code></pre> 
  <p>新列表</p> 
  <pre><code class="prism language-python"><span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">,</span> <span class="token number">7</span> <span class="token punctuation">,</span> <span class="token number">8</span> <span class="token punctuation">,</span> <span class="token number">9</span> <span class="token punctuation">,</span> <span class="token number">10</span> <span class="token punctuation">,</span> <span class="token number">11</span> <span class="token punctuation">,</span> <span class="token number">12</span> <span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">]</span>
np_arr  <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span>范围<span class="token punctuation">(</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">11</span> <span class="token punctuation">)</span><span class="token punctuation">)</span>
 np_arr  <span class="token operator">+</span>  <span class="token number">2</span>
</code></pre> 
  <p>数组([ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])</p> 
  <p>对于具有线性关系的量,我们使用线性方程。让我们看看下面的例子:</p> 
  <pre><code class="prism language-python">温度 <span class="token operator">=</span>  np。数组<span class="token punctuation">(</span><span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
 pressure  <span class="token operator">=</span>  temp  <span class="token operator">*</span>  <span class="token number">2</span>  <span class="token operator">+</span>  <span class="token number">5</span> 
pressure
</code></pre> 
  <p>数组([ 7, 9, 11, 13, 15])</p> 
  <pre><code class="prism language-python">PLT。绘图(温度,压力)
 plt。xlabel(<span class="token string">'摄氏温度'</span>)
 plt。ylabel(<span class="token string">'atm 中的压力'</span>)
 plt。标题(<span class="token string">'温度与压力'</span>)
 plt。xticks(NP。人气指数(<span class="token number">0</span>,<span class="token number">6</span>,步骤<span class="token operator">=</span> <span class="token number">0.5</span>))
 PLT。显示<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/18e82ed8cbd74f4d9af8cd63bbac5b62.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/18e82ed8cbd74f4d9af8cd63bbac5b62.jpg" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第3张图片" width="386" height="278" style="border:1px solid black;"></a></p> 
  <p>使用 numpy 绘制高斯正态分布。如下所示,numpy 可以生成随机数。要创建随机样本,我们需要均值(mu)、sigma(标准差)、数据点数。</p> 
  <pre><code class="prism language-python">mu  <span class="token operator">=</span>  <span class="token number">28</span>
西格玛 <span class="token operator">=</span>  <span class="token number">15</span> 个
样本 <span class="token operator">=</span>  <span class="token number">100000</span>

x  <span class="token operator">=</span>  np。随机的。正常(mu <span class="token punctuation">,</span> sigma <span class="token punctuation">,</span>样本)
 ax  <span class="token operator">=</span>  sns。分布图<span class="token punctuation">(</span> x <span class="token punctuation">)</span><span class="token punctuation">;</span>
斧头。设置<span class="token punctuation">(</span> xlabel <span class="token operator">=</span> <span class="token string">"x"</span> <span class="token punctuation">,</span> ylabel <span class="token operator">=</span> <span class="token string">'y'</span> <span class="token punctuation">)</span>
 plt。显示<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/4beaadeb30ef4f14b25c73b5e0cbcdd3.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/4beaadeb30ef4f14b25c73b5e0cbcdd3.jpg" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第4张图片" width="400" height="261" style="border:1px solid black;"></a></p> 
  <p>总而言之,与 python 列表的主要区别是:</p> 
  <ol> 
   <li>数组支持向量化操作,而列表不支持。</li> 
   <li>一旦创建了数组,就不能更改其大小。您将不得不创建一个新阵列或覆盖现有阵列。</li> 
   <li>每个数组都有一个且只有一个 dtype。其中的所有项目都应该是那个 dtype。</li> 
   <li>等效的 numpy 数组比 Python 列表占用的空间少得多。</li> 
   <li>numpy 数组支持布尔索引。</li> 
  </ol> 
  <h1>第 25 天 - Pandas</h1> 
  <p>Pandas 是一种开源、高性能、易于使用的 Python 编程语言的数据结构和数据分析工具。Pandas 添加了数据结构和工具,旨在处理类似表格的数据,即Series和Data Frames。Pandas 提供了用于数据操作的工具:</p> 
  <ol> 
   <li>重塑</li> 
   <li>合并</li> 
   <li>排序</li> 
   <li>切片</li> 
   <li>聚合</li> 
   <li>插补。如果您使用的是 anaconda,则无需安装 pandas。</li> 
  </ol> 
  <h2>25.1安装pandas</h2> 
  <p>对于 Mac:</p> 
  <blockquote> 
   <p>pip 安装 conda<br> conda 安装 pandas</p> 
  </blockquote> 
  <p>对于 Windows:</p> 
  <blockquote> 
   <p>pip 安装 conda<br> pip 安装 熊猫</p> 
  </blockquote> 
  <p>Pandas 数据结构基于Series和DataFrames。</p> 
  <p>一个系列是一列和一个数据帧是一个多维表的集合组成系列。为了创建一个pandas系列,我们应该使用numpy来创建一个一维数组或一个python列表。让我们看一个系列的例子:</p> 
  <p>命名pandas系列</p> 
  <p><a href="http://img.e-com-net.com/image/info8/19e0a0c8fd64436bb4a872272a9c5091.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/19e0a0c8fd64436bb4a872272a9c5091.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第5张图片" width="231" height="194" style="border:1px solid black;"></a></p> 
  <p>国家系列<br> <a href="http://img.e-com-net.com/image/info8/8db922e9c7fb4b5298e62c103fa19cef.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/8db922e9c7fb4b5298e62c103fa19cef.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第6张图片" width="216" height="187" style="border:1px solid black;"></a></p> 
  <p>城市系列<br> <a href="http://img.e-com-net.com/image/info8/235d1178d6cb4fcfb62a0abc43f0621a.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/235d1178d6cb4fcfb62a0abc43f0621a.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第7张图片" width="218" height="193" style="border:1px solid black;"></a></p> 
  <p>如您所见,pandas 系列只是一列数据。如果我们想要多列,我们使用数据框。下面的示例显示了 Pandas DataFrames。</p> 
  <p>让我们看看一个 Pandas 数据框的例子:</p> 
  <p><a href="http://img.e-com-net.com/image/info8/f0e4c86ffb9c464fbab8280d8f3784d6.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/f0e4c86ffb9c464fbab8280d8f3784d6.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第8张图片" width="575" height="187" style="border:1px solid black;"></a></p> 
  <p>数据框是行和列的集合。看下表;它比上面的例子有更多的列:</p> 
  <p><a href="http://img.e-com-net.com/image/info8/19c548f8dfd64630a886bac657c6ac34.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/19c548f8dfd64630a886bac657c6ac34.jpg" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第9张图片" width="650" height="141" style="border:1px solid black;"></a></p> 
  <p>接下来,我们将看到如何导入pandas以及如何使用pandas创建Series和DataFrames</p> 
  <h2>导入pandas</h2> 
  <pre><code class="prism language-python"><span class="token keyword">import</span>  pandas  <span class="token keyword">as</span>  pd  <span class="token comment"># 将pandas 导入为pd </span>
<span class="token keyword">import</span>  numpy   <span class="token keyword">as</span>  np  <span class="token comment"># 将numpy 导入为np</span>
</code></pre> 
  <h2>25.2使用默认索引创建 Pandas 系列</h2> 
  <pre><code class="prism language-python">nums  <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span>
 s  <span class="token operator">=</span>  pd。系列<span class="token punctuation">(</span> nums <span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> s <span class="token punctuation">)</span>
    <span class="token number">0</span> <span class="token number">1</span>
    <span class="token number">1</span> <span class="token number">2</span>
    <span class="token number">2</span> <span class="token number">3</span>
    <span class="token number">3</span> <span class="token number">4</span>
    <span class="token number">4</span> <span class="token number">5</span>
    数据类型:int64
</code></pre> 
  <h2>25.3使用自定义索引创建 Pandas 系列</h2> 
  <pre><code class="prism language-python">nums  <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span>
 s  <span class="token operator">=</span>  pd。系列<span class="token punctuation">(</span> nums <span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">,</span> <span class="token number">4</span> <span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> s <span class="token punctuation">)</span>
    <span class="token number">1</span> <span class="token number">1</span>
    <span class="token number">2</span> <span class="token number">2</span>
    <span class="token number">3</span> <span class="token number">3</span>
    <span class="token number">4</span> <span class="token number">4</span>
    <span class="token number">5</span> <span class="token number">5</span>
    数据类型:int64
水果 <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token string">'Orange'</span> <span class="token punctuation">,</span> <span class="token string">'Banana'</span> <span class="token punctuation">,</span> <span class="token string">'Mango'</span> <span class="token punctuation">]</span>
水果 <span class="token operator">=</span>  pd <span class="token punctuation">.</span> 系列(水果,指数<span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">1</span>,<span class="token number">2</span>,<span class="token number">3</span> <span class="token punctuation">]</span>)
打印(水果)
    <span class="token number">1</span> 橙色
    <span class="token number">2</span> 香蕉
    <span class="token number">3</span> 芒果
    数据类型:对象
</code></pre> 
  <h2>25.4从字典创建 Pandas 系列</h2> 
  <pre><code class="prism language-python">dct  <span class="token operator">=</span> <span class="token punctuation">{
     </span> <span class="token string">'name'</span> <span class="token punctuation">:</span> <span class="token string">'Asabeneh'</span> <span class="token punctuation">,</span> <span class="token string">'country'</span> <span class="token punctuation">:</span> <span class="token string">'芬兰'</span> <span class="token punctuation">,</span> <span class="token string">'city'</span> <span class="token punctuation">:</span> <span class="token string">'赫尔辛基'</span> <span class="token punctuation">}</span>
s  <span class="token operator">=</span>  pd。系列<span class="token punctuation">(</span> dct <span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> s <span class="token punctuation">)</span>
    姓名 Asabeneh
    国家芬兰
    赫尔辛基市
    数据类型:对象
</code></pre> 
  <h2>25.5创建一个常量 Pandas 系列</h2> 
  <pre><code class="prism language-python">s  <span class="token operator">=</span>  pd。系列<span class="token punctuation">(</span> <span class="token number">10</span> <span class="token punctuation">,</span> index  <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">,</span> <span class="token number">3</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> s <span class="token punctuation">)</span>
    <span class="token number">1</span> <span class="token number">10</span>
    <span class="token number">2</span> <span class="token number">10</span>
    <span class="token number">3</span> <span class="token number">10</span>
    数据类型:int64
</code></pre> 
  <h2>25.6使用 Linspace 创建 Pandas 系列</h2> 
  <pre><code class="prism language-python">s  <span class="token operator">=</span>  pd。系列<span class="token punctuation">(</span> np <span class="token punctuation">.</span> linspace <span class="token punctuation">(</span> <span class="token number">5</span> <span class="token punctuation">,</span> <span class="token number">20</span> <span class="token punctuation">,</span> <span class="token number">10</span> <span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment"># linspace(starting, end, items)</span>
打印<span class="token punctuation">(</span> s <span class="token punctuation">)</span>
    <span class="token number">0</span> <span class="token number">5.000000</span>
    <span class="token number">1</span> <span class="token number">6.666667</span>
    <span class="token number">2</span> <span class="token number">8.333333</span>
    <span class="token number">3</span> <span class="token number">10.000000</span>
    <span class="token number">4</span> <span class="token number">11.666667</span>
    <span class="token number">5</span> <span class="token number">13.333333</span>
    <span class="token number">6</span> <span class="token number">15.000000</span>
    <span class="token number">7</span> <span class="token number">16.666667</span>
    <span class="token number">8</span> <span class="token number">18.333333</span>
    <span class="token number">9</span> <span class="token number">20.000000</span>
    数据类型:float64
</code></pre> 
  <h2>25.7数据帧</h2> 
  <p>Pandas 数据框可以用不同的方式创建。</p> 
  <h3>从列表列表创建数据帧</h3> 
  <pre><code class="prism language-python">数据 <span class="token operator">=</span> <span class="token punctuation">[</span>
    <span class="token punctuation">[</span> “阿萨本尼”、“芬兰”、“赫尔辛克” <span class="token punctuation">]</span>、
    <span class="token punctuation">[</span> <span class="token string">'大卫'</span>,<span class="token string">'英国'</span>,<span class="token string">'伦敦'</span> <span class="token punctuation">]</span>,
    <span class="token punctuation">[</span> “约翰”、“瑞典”、“斯德哥尔摩” <span class="token punctuation">]</span>
<span class="token punctuation">]</span>
df  <span class="token operator">=</span>  pd。DataFrame <span class="token punctuation">(</span> data <span class="token punctuation">,</span> columns <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token string">'Names'</span> <span class="token punctuation">,</span> <span class="token string">'Country'</span> <span class="token punctuation">,</span> <span class="token string">'City'</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> df <span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/08ffd0f5c3b5428f9fa92173e70618cb.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/08ffd0f5c3b5428f9fa92173e70618cb.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第10张图片" width="318" height="183" style="border:1px solid black;"></a></p> 
  <h2>25.8使用字典创建 DataFrame</h2> 
  <pre><code class="prism language-python">data  <span class="token operator">=</span> <span class="token punctuation">{
     </span> <span class="token string">'Name'</span> <span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token string">'Asabeneh'</span> <span class="token punctuation">,</span> <span class="token string">'David'</span> <span class="token punctuation">,</span> <span class="token string">'John'</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">'国家'</span> <span class="token punctuation">:</span><span class="token punctuation">[</span>
     <span class="token string">'芬兰'</span> <span class="token punctuation">,</span> <span class="token string">'英国'</span> <span class="token punctuation">,</span> <span class="token string">'瑞典'</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string">'城市'</span> <span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token string">'赫尔斯基'</span> <span class="token punctuation">,</span> <span class="token string">'伦敦'</span> <span class="token punctuation">,</span> <span class="token string">'斯德哥尔摩'</span> <span class="token punctuation">]</span><span class="token punctuation">}</span>
 df  <span class="token operator">=</span>  pd <span class="token punctuation">.</span> DataFrame(数据)
打印(df)
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/1642e89f3dfb4902813ec533108c725c.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/1642e89f3dfb4902813ec533108c725c.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第11张图片" width="310" height="179" style="border:1px solid black;"></a></p> 
  <h2>25.9从字典列表创建数据帧</h2> 
  <pre><code class="prism language-python">数据 <span class="token operator">=</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{
     </span> <span class="token string">'姓名'</span> <span class="token punctuation">:</span> <span class="token string">'Asabeneh'</span> <span class="token punctuation">,</span> <span class="token string">'国家'</span> <span class="token punctuation">:</span> <span class="token string">'芬兰'</span> <span class="token punctuation">,</span> <span class="token string">'城市'</span> <span class="token punctuation">:</span> <span class="token string">'赫尔辛基'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">{
     </span> <span class="token string">'姓名'</span>:<span class="token string">'大卫'</span>,<span class="token string">'国家'</span>:<span class="token string">'英国'</span>,<span class="token string">'城市'</span>:<span class="token string">'伦敦'</span> <span class="token punctuation">}</span>,
    <span class="token punctuation">{
     </span> <span class="token string">'姓名'</span>:<span class="token string">'约翰'</span>,<span class="token string">'国家'</span>:<span class="token string">'瑞典'</span>,<span class="token string">'城市'</span>:<span class="token string">'斯德哥尔摩'</span> <span class="token punctuation">}</span><span class="token punctuation">]</span>
 df  <span class="token operator">=</span>  pd <span class="token punctuation">.</span> DataFrame(数据)
打印(df)
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/0ca80048917d463ca7389d8ca2710b2f.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/0ca80048917d463ca7389d8ca2710b2f.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第12张图片" width="321" height="189" style="border:1px solid black;"></a></p> 
  <h2>25.10使用 Pandas 读取 CSV 文件</h2> 
  <p>要下载 CSV 文件,本例中需要什么,控制台/命令行就足够了:</p> 
  <pre><code class="prism language-python">curl <span class="token operator">-</span>O https<span class="token punctuation">:</span><span class="token operator">//</span>raw<span class="token punctuation">.</span>githubusercontent<span class="token punctuation">.</span>com<span class="token operator">/</span>Asabeneh<span class="token operator">/</span><span class="token number">30</span><span class="token operator">-</span>Days<span class="token operator">-</span>Of<span class="token operator">-</span>Python<span class="token operator">/</span>master<span class="token operator">/</span>data<span class="token operator">/</span>weight<span class="token operator">-</span>height<span class="token punctuation">.</span>csv
</code></pre> 
  <p>将下载的文件放在您的工作目录中。</p> 
  <pre><code class="prism language-python">将 Pandas 导入为 pd

df  <span class="token operator">=</span>  pd。read_csv <span class="token punctuation">(</span> <span class="token string">'weight-height.csv'</span> <span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> df <span class="token punctuation">)</span>
</code></pre> 
  <h2>25.11数据探索</h2> 
  <p>让我们使用 head() 仅读取前 5 行</p> 
  <pre><code class="prism language-python"><span class="token keyword">print</span> <span class="token punctuation">(</span> df <span class="token punctuation">.</span> head <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment"># 给五行我们可以通过将参数传递给 head() 方法来增加行数</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/98d513e77f6c4afe9dc991b46db2e120.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/98d513e77f6c4afe9dc991b46db2e120.jpg" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第13张图片" width="320" height="265" style="border:1px solid black;"></a><br> 让我们还使用 tail() 方法探索数据帧的最后记录。</p> 
  <pre><code class="prism language-python">打印(DF。尾()) #尾巴给最后的五排,我们可以通过传递参数尾法提高行
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/4c700cd50f20472492421d100efc1a39.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/4c700cd50f20472492421d100efc1a39.jpg" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第14张图片" width="362" height="266" style="border:1px solid black;"></a></p> 
  <p>如您所见,csv 文件有三行:性别、身高和体重。如果 DataFrame 有很长的行,就很难知道所有的列。因此,我们应该使用一种方法来知道列。我们不知道行数。让我们使用形状肉类。</p> 
  <pre><code class="prism language-python"><span class="token keyword">print</span> <span class="token punctuation">(</span> df <span class="token punctuation">.</span> shape <span class="token punctuation">)</span> <span class="token comment"># 如你所见 10000 行和三列</span>
<span class="token punctuation">(</span><span class="token number">10000</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span>
</code></pre> 
  <p>让我们使用列获取所有列。</p> 
  <pre><code class="prism language-python">打印(df。列)
Index<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">'Gender'</span><span class="token punctuation">,</span> <span class="token string">'Height'</span><span class="token punctuation">,</span> <span class="token string">'Weight'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> dtype<span class="token operator">=</span><span class="token string">'object'</span><span class="token punctuation">)</span>
</code></pre> 
  <p>现在,让我们使用列键获取特定列</p> 
  <pre><code class="prism language-python">heights  <span class="token operator">=</span>  df <span class="token punctuation">[</span> <span class="token string">'Height'</span> <span class="token punctuation">]</span> <span class="token comment"># 这是一个系列</span>
打印(高度)
    <span class="token number">0</span> <span class="token number">73.847017</span>
    <span class="token number">1</span> <span class="token number">68.781904</span>
    <span class="token number">2</span> <span class="token number">74.110105</span>
    <span class="token number">3</span> <span class="token number">71.730978</span>
    <span class="token number">4</span> <span class="token number">69.881796</span>
              <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>    
    <span class="token number">9995</span> <span class="token number">66.172652</span>
    <span class="token number">9996</span> <span class="token number">67.067155</span>
    <span class="token number">9997</span> <span class="token number">63.867992</span>
    <span class="token number">9998</span> <span class="token number">69.034243</span>
    <span class="token number">9999</span> <span class="token number">61.944246</span>
    名称:高度,长度:<span class="token number">10000</span>,数据类型:float64
weights  <span class="token operator">=</span>  df <span class="token punctuation">[</span> <span class="token string">'Weight'</span> <span class="token punctuation">]</span> <span class="token comment"># 这是一个系列</span>
打印(重量)
    <span class="token number">0</span> <span class="token number">241.893563</span>
    <span class="token number">1</span> <span class="token number">162.310473</span>
    <span class="token number">2</span> <span class="token number">212.740856</span>
    <span class="token number">3</span> <span class="token number">220.042470</span>
    <span class="token number">4</span> <span class="token number">206.349801</span>
               <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>    
    <span class="token number">9995</span> <span class="token number">136.777454</span>
    <span class="token number">9996</span> <span class="token number">170.867906</span>
    <span class="token number">9997</span> <span class="token number">128.475319</span>
    <span class="token number">9998</span> <span class="token number">163.852461</span>
    <span class="token number">9999</span> <span class="token number">113.649103</span>
    名称:重量,长度:<span class="token number">10000</span>,dtype:float64
打印(<span class="token builtin">len</span>(高度)<span class="token operator">==</span>  <span class="token builtin">len</span>(权重))
<span class="token boolean">True</span>
</code></pre> 
  <p>describe() 方法提供数据集的描述性统计值。</p> 
  <pre><code class="prism language-python"><span class="token keyword">print</span> <span class="token punctuation">(</span> heights <span class="token punctuation">.</span> describe <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment"># 给出高度数据的统计信息</span>
    数 <span class="token number">10000.000000</span>
    平均 <span class="token number">66.367560</span>
    标准 <span class="token number">3.847528</span>
    分钟 <span class="token number">54.263133</span>
    <span class="token number">25</span><span class="token operator">%</span> <span class="token number">63.505620</span>
    <span class="token number">50</span><span class="token operator">%</span> <span class="token number">66.318070</span>
    <span class="token number">75</span><span class="token operator">%</span> <span class="token number">69.174262</span>
    最大 <span class="token number">78.998742</span>
    名称:高度,数据类型:float64
打印(权重。描述())
    数 <span class="token number">10000.000000</span>
    平均 <span class="token number">161.440357</span>
    标准 <span class="token number">32.108439</span>
    最低 <span class="token number">64.700127</span>
    <span class="token number">25</span><span class="token operator">%</span> <span class="token number">135.818051</span>
    <span class="token number">50</span><span class="token operator">%</span> <span class="token number">161.212928</span>
    <span class="token number">75</span><span class="token operator">%</span> <span class="token number">187.169525</span>
    最大 <span class="token number">269.989699</span>
    名称:重量,数据类型:float64
</code></pre> 
  <pre><code class="prism language-python"><span class="token keyword">print</span> <span class="token punctuation">(</span> df <span class="token punctuation">.</span> describe <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>   <span class="token comment"># describe 还可以给出来自数据帧的统计信息</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/1273783618524e1a802d91824d22d723.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/1273783618524e1a802d91824d22d723.jpg" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第15张图片" width="363" height="379" style="border:1px solid black;"></a></p> 
  <p>与 describe() 类似,info() 方法也提供有关数据集的信息。</p> 
  <h2>25.12修改数据帧</h2> 
  <p>修改DataFrame: * 我们可以创建一个新的DataFrame * 我们可以创建一个新列并将其添加到DataFrame, * 我们可以从DataFrame 中删除现有列, * 我们可以修改DataFrame 中的现有列, * 我们可以更改 DataFrame 中列值的数据类型</p> 
  <h2>25.13创建数据帧</h2> 
  <p>与往常一样,首先我们导入必要的包。现在,让我们导入 pandas 和 numpy,这两个最好的朋友。</p> 
  <pre><code class="prism language-python">将Pandas 导入为 pd
将 numpy 导入为 np
数据 <span class="token operator">=</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{
     </span> “姓名”:“阿萨本尼”,“国家”:“芬兰”,“城市”:“赫尔辛基” <span class="token punctuation">}</span>,
    <span class="token punctuation">{
     </span> “姓名”:“大卫”,“国家”:“英国”,“城市”:“伦敦” <span class="token punctuation">}</span>,
    <span class="token punctuation">{
     </span> “姓名”:“约翰”,“国家”:“瑞典”,“城市”:“斯德哥尔摩” <span class="token punctuation">}</span><span class="token punctuation">]</span>
 df  <span class="token operator">=</span>  pd <span class="token punctuation">.</span> DataFrame(数据)
打印(df)
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/05b3a63f2c704a669413facb9e76fa01.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/05b3a63f2c704a669413facb9e76fa01.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第16张图片" width="315" height="179" style="border:1px solid black;"></a></p> 
  <p>向 DataFrame 添加列就像向字典添加键。</p> 
  <p>首先让我们使用前面的示例来创建一个 DataFrame。创建 DataFrame 后,我们将开始修改列和列值。</p> 
  <h2>25.14添加新列</h2> 
  <p>让我们在 DataFrame 中添加一个权重列</p> 
  <pre><code class="prism language-python">权重 <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">74</span> <span class="token punctuation">,</span> <span class="token number">78</span> <span class="token punctuation">,</span> <span class="token number">69</span> <span class="token punctuation">]</span>
 df <span class="token punctuation">[</span> <span class="token string">'Weight'</span> <span class="token punctuation">]</span> <span class="token operator">=</span> 权重
df
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/6c8a658531184986a0c314192f72d2ea.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/6c8a658531184986a0c314192f72d2ea.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第17张图片" width="384" height="183" style="border:1px solid black;"></a></p> 
  <p>让我们在 DataFrame 中添加一个高度列</p> 
  <pre><code class="prism language-python">高度 <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">173</span> <span class="token punctuation">,</span> <span class="token number">175</span> <span class="token punctuation">,</span> <span class="token number">169</span> <span class="token punctuation">]</span>
 df <span class="token punctuation">[</span> <span class="token string">'高度'</span> <span class="token punctuation">]</span> <span class="token operator">=</span> 高度
打印<span class="token punctuation">(</span> df <span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/2ea3d6ffbdf64359b0fd09a213be9da9.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/2ea3d6ffbdf64359b0fd09a213be9da9.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第18张图片" width="427" height="177" style="border:1px solid black;"></a></p> 
  <p>正如您在上面的 DataFrame 中看到的,我们确实添加了新的列,重量和高度。让我们通过使用他们的体重和身高计算他们的 BMI 来添加一个额外的列,称为 BMI(身体质量指数)。BMI 是质量除以身高的平方(以米为单位)- 体重/身高 * 身高。</p> 
  <p>如您所见,高度以厘米为单位,因此我们应该将其更改为米。让我们修改高度行。</p> 
  <h2>25.15修改列值</h2> 
  <pre><code class="prism language-python">df <span class="token punctuation">[</span> <span class="token string">'高度'</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  df <span class="token punctuation">[</span> <span class="token string">'高度'</span> <span class="token punctuation">]</span> <span class="token operator">*</span>  <span class="token number">0.01</span> 
df
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/f68103bbf35e4fcca6f64b2c76f723f4.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/f68103bbf35e4fcca6f64b2c76f723f4.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第19张图片" width="432" height="179" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-python"><span class="token comment"># 使用函数使我们的代码更简洁,但是你可以不用一个来计算 bmi </span>
<span class="token keyword">def</span>  <span class="token function">calculate_bmi</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
     weights  <span class="token operator">=</span>  df <span class="token punctuation">[</span> <span class="token string">'Weight'</span> <span class="token punctuation">]</span>
     heights  <span class="token operator">=</span>  df <span class="token punctuation">[</span> <span class="token string">'Height'</span> <span class="token punctuation">]</span>
     bmi  <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
     <span class="token keyword">for</span>  w <span class="token punctuation">,</span> h  <span class="token keyword">in</span>  <span class="token builtin">zip</span> <span class="token punctuation">(</span> weights <span class="token punctuation">,</span>高度<span class="token punctuation">)</span><span class="token punctuation">:</span>
         b  <span class="token operator">=</span>  w <span class="token operator">/</span> <span class="token punctuation">(</span> h <span class="token operator">*</span> h <span class="token punctuation">)</span>
         bmi。追加<span class="token punctuation">(</span> b <span class="token punctuation">)</span>
    返回 体重指数
    
bmi  <span class="token operator">=</span>  calculate_bmi <span class="token punctuation">(</span><span class="token punctuation">)</span>
df <span class="token punctuation">[</span> <span class="token string">'BMI'</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  bmi 
df
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/2ce68f9f385242a9872fc644154294ef.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/2ce68f9f385242a9872fc644154294ef.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第20张图片" width="527" height="183" style="border:1px solid black;"></a></p> 
  <h2>25.16格式化 DataFrame 列</h2> 
  <p>DataFrame 的 BMI 列值是浮点数,小数点后有许多有效数字。让我们将其更改为一位有效数字。</p> 
  <pre><code class="prism language-python">df <span class="token punctuation">[</span> <span class="token string">'BMI'</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  <span class="token builtin">round</span> <span class="token punctuation">(</span> df <span class="token punctuation">[</span> <span class="token string">'BMI'</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">)</span>
打印<span class="token punctuation">(</span> df <span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/f6cb4ab0ebcc43dbbcb8ba57d3d0435f.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/f6cb4ab0ebcc43dbbcb8ba57d3d0435f.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第21张图片" width="518" height="186" style="border:1px solid black;"></a></p> 
  <p>DataFrame 中的信息似乎还没有完成,让我们添加出生年份和当前年份列。</p> 
  <pre><code class="prism language-python">birth_year  <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token string">'1769'</span> <span class="token punctuation">,</span> <span class="token string">'1985'</span> <span class="token punctuation">,</span> <span class="token string">'1990'</span> <span class="token punctuation">]</span>
 current_year  <span class="token operator">=</span>  pd。系列<span class="token punctuation">(</span> <span class="token number">2020</span> <span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">,</span> <span class="token number">2</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
 df <span class="token punctuation">[</span> <span class="token string">'Birth Year'</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  birth_year 
df <span class="token punctuation">[</span> <span class="token string">'Current Year'</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  current_year 
df
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/0210e1481554450a86dd2835b29211b6.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/0210e1481554450a86dd2835b29211b6.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第22张图片" width="676" height="183" style="border:1px solid black;"></a></p> 
  <h2>25.17检查列值的数据类型</h2> 
  <pre><code class="prism language-python">打印(DF,重量,D型)
    数据类型(<span class="token string">' int64 '</span>)
df <span class="token punctuation">[</span> <span class="token string">'出生年份'</span> <span class="token punctuation">]</span>。dtype  <span class="token comment"># 它给出字符串对象,我们应该将其更改为数字</span>
df <span class="token punctuation">[</span> <span class="token string">'出生年份'</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  df <span class="token punctuation">[</span> <span class="token string">'出生年份'</span> <span class="token punctuation">]</span>。astype <span class="token punctuation">(</span> <span class="token string">'int'</span> <span class="token punctuation">)</span>
 <span class="token keyword">print</span> <span class="token punctuation">(</span> df <span class="token punctuation">[</span> <span class="token string">'Birth Year'</span> <span class="token punctuation">]</span><span class="token punctuation">.</span> dtype <span class="token punctuation">)</span> <span class="token comment"># 现在检查数据类型</span>
    数据类型(<span class="token string">' int32 '</span>)
</code></pre> 
  <p>现在与当年相同:</p> 
  <pre><code class="prism language-python">df <span class="token punctuation">[</span> <span class="token string">'当年'</span> <span class="token punctuation">]</span> <span class="token operator">=</span>  df <span class="token punctuation">[</span> <span class="token string">'当年'</span> <span class="token punctuation">]</span>。astype <span class="token punctuation">(</span> <span class="token string">'int'</span> <span class="token punctuation">)</span>
 df <span class="token punctuation">[</span> <span class="token string">'本年'</span> <span class="token punctuation">]</span>。数据类型
    数据类型(<span class="token string">' int32 '</span>)
</code></pre> 
  <p>现在,出生年份和当前年份的列值为整数。我们可以计算年龄。</p> 
  <pre><code class="prism language-python">年龄 <span class="token operator">=</span>  df <span class="token punctuation">[</span> <span class="token string">'本年'</span> <span class="token punctuation">]</span> <span class="token operator">-</span>  df <span class="token punctuation">[</span> <span class="token string">'出生年份'</span> <span class="token punctuation">]</span>
年龄
<span class="token number">0</span>    <span class="token number">251</span>
<span class="token number">1</span>     <span class="token number">35</span>
<span class="token number">2</span>     <span class="token number">30</span>
dtype<span class="token punctuation">:</span> int32
df <span class="token punctuation">[</span> <span class="token string">'年龄'</span> <span class="token punctuation">]</span> <span class="token operator">=</span> 年龄
打印(df)
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/061b31948bdf4d0e8864011ad4568c39.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/061b31948bdf4d0e8864011ad4568c39.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第23张图片" width="738" height="176" style="border:1px solid black;"></a></p> 
  <p>第一排的人迄今活了251岁。一个人不可能活这么久。要么是打字错误,要么是数据被煮熟了。因此,让我们用列的平均值填充该数据,而不包括异常值。</p> 
  <p>平均值 = (35 + 30)/ 2</p> 
  <pre><code class="prism language-python">mean  <span class="token operator">=</span> <span class="token punctuation">(</span> <span class="token number">35</span>  <span class="token operator">+</span>  <span class="token number">30</span> <span class="token punctuation">)</span> <span class="token operator">/</span>  <span class="token number">2</span> 
<span class="token keyword">print</span> <span class="token punctuation">(</span> <span class="token string">'Mean: '</span> <span class="token punctuation">,</span> mean <span class="token punctuation">)</span>	 <span class="token comment">#在输出中添加一些描述很好,所以我们知道什么是什么</span>
   平均值:<span class="token number">32.5</span>
</code></pre> 
  <h2>25.18布尔索引</h2> 
  <pre><code class="prism language-python">打印<span class="token punctuation">(</span> df <span class="token punctuation">[</span> df <span class="token punctuation">[</span> <span class="token string">'年龄'</span> <span class="token punctuation">]</span> <span class="token operator">></span>  <span class="token number">120</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/7e42bd636831415bb23142c377e2841d.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/7e42bd636831415bb23142c377e2841d.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第24张图片" width="723" height="102" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-python">打印<span class="token punctuation">(</span> df <span class="token punctuation">[</span> df <span class="token punctuation">[</span> <span class="token string">'年龄'</span> <span class="token punctuation">]</span> <span class="token operator"><</span>  <span class="token number">120</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/9306ffb6ee504946a64db9c620acc483.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/9306ffb6ee504946a64db9c620acc483.png" alt="简洁易懂,初学者挑战学习Python编程30天 (四)_第25张图片" width="698" height="147" style="border:1px solid black;"></a></p> 
  <p>初学者挑战学习Python编程30天还有最后一节续集就要结束了,感兴趣了解下面的学习内容,记得关注我。</p> 
 </div> 
</div>
                            </div>
                        </div>
                    </div>
                    <!--PC和WAP自适应版-->
                    <div id="SOHUCS" sid="1445164669760221184"></div>
                    <script type="text/javascript" src="/views/front/js/chanyan.js"></script>
                    <!-- 文章页-底部 动态广告位 -->
                    <div class="youdao-fixed-ad" id="detail_ad_bottom"></div>
                </div>
                <div class="col-md-3">
                    <div class="row" id="ad">
                        <!-- 文章页-右侧1 动态广告位 -->
                        <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_1"> </div>
                        </div>
                        <!-- 文章页-右侧2 动态广告位 -->
                        <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_2"></div>
                        </div>
                        <!-- 文章页-右侧3 动态广告位 -->
                        <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_3"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(Python编程30天,python,经验分享,初学者挑战)</h4>
        <div id="paradigm-article-related">
            <div class="recommend-post mb30">
                <ul class="widget-links">
                    <li><a href="/article/1880629045926883328.htm"
                           title="WebSocket 安全实践:从认证到加密" target="_blank">WebSocket 安全实践:从认证到加密</a>
                        <span class="text-muted"></span>

                        <div>在前三篇文章中,我们深入探讨了WebSocket的基础原理、服务端开发和客户端实现。今天,让我们把重点放在安全性上,看看如何构建一个安全可靠的WebSocket应用。我曾在一个金融项目中,通过实施多层安全机制,成功防御了多次恶意攻击尝试。安全挑战WebSocket应用面临的主要安全挑战包括:身份认证数据加密跨站点WebSocket劫持(CSWSH)拒绝服务攻击(DoS)中间人攻击让我们逐一解决这些</div>
                    </li>
                    <li><a href="/article/1880629041946488832.htm"
                           title="WebSocket 基础入门:协议原理与实现" target="_blank">WebSocket 基础入门:协议原理与实现</a>
                        <span class="text-muted"></span>

                        <div>在现代网页应用中,WebSocket就像是一条永不断开的高速公路,让客户端和服务器之间的实时通信变得畅通无阻。记得在一个实时协作项目中,我们通过使用WebSocket,让用户的操作延迟从300ms降到了50ms。今天,我想和大家分享WebSocket的基础知识和实现方案。WebSocket是什么?WebSocket是一种在单个TCP连接上进行全双工通信的协议。它提供了在客户端和服务器之间建立持久连</div>
                    </li>
                    <li><a href="/article/1880629043305443328.htm"
                           title="Python 潮流周刊#84:2024 年 Python 的最佳实践(摘要)" target="_blank">Python 潮流周刊#84:2024 年 Python 的最佳实践(摘要)</a>
                        <span class="text-muted"></span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>本周刊由Python猫出品,精心筛选国内外的250+信息源,为你挑选最值得分享的文章、教程、开源项目、软件工具、播客和视频、热门话题等内容。愿景:帮助所有读者精进Python技术,并增长职业和副业的收入。分享了12篇文章,12个开源项目,全文2200字。以下是本期摘要:文章&教程①现代Python开发的良好实践②2024年最先进的Python③回顾一年:2024年的Flask④介绍Annotate</div>
                    </li>
                    <li><a href="/article/1880628253392171008.htm"
                           title="Python基于matplotlib-scalebar库绘制比例尺" target="_blank">Python基于matplotlib-scalebar库绘制比例尺</a>
                        <span class="text-muted">懒大王爱吃狼</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/matplotlib/1.htm">matplotlib</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/%E8%87%AA%E5%8A%A8%E5%8C%96/1.htm">自动化</a><a class="tag" taget="_blank" href="/search/Python%E5%9F%BA%E7%A1%80/1.htm">Python基础</a><a class="tag" taget="_blank" href="/search/opencv/1.htm">opencv</a>
                        <div>在Python中,你可以使用matplotlib-scalebar库来在图表上绘制比例尺。这个库是matplotlib的一个扩展,专门用于在绘图时添加比例尺。以下是一个简单的示例,展示了如何使用matplotlib-scalebar来绘制带有比例尺的图表。首先,你需要安装matplotlib-scalebar库。如果你还没有安装它,可以使用以下命令来安装:pipinstallmatplotlib-</div>
                    </li>
                    <li><a href="/article/1880627276027064320.htm"
                           title="Python 潮流周刊#77:Python 依赖管理就像垃圾场火灾?(摘要)" target="_blank">Python 潮流周刊#77:Python 依赖管理就像垃圾场火灾?(摘要)</a>
                        <span class="text-muted"></span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>本周刊由Python猫出品,精心筛选国内外的250+信息源,为你挑选最值得分享的文章、教程、开源项目、软件工具、播客和视频、热门话题等内容。愿景:帮助所有读者精进Python技术,并增长职业和副业的收入。分享了12篇文章,12个开源项目,2则热门讨论,全文2200字。以下是本期摘要:文章&教程①Python依赖管理一种垃圾场火灾②Python的膨胀:精细的项目间依赖关系分析③分享我的Django项</div>
                    </li>
                    <li><a href="/article/1880627023014064128.htm"
                           title="Python 潮流周刊#74:创下吉尼斯世界记录的 Python 编程课(摘要)" target="_blank">Python 潮流周刊#74:创下吉尼斯世界记录的 Python 编程课(摘要)</a>
                        <span class="text-muted"></span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>本周刊由Python猫出品,精心筛选国内外的250+信息源,为你挑选最值得分享的文章、教程、开源项目、软件工具、播客和视频、热门话题等内容。愿景:帮助所有读者精进Python技术,并增长职业和副业的收入。本期分享了12篇文章,12个开源项目,2则音视频,全文2300字。好消息:即日起至万圣节(12.31),周刊限时99元/年,欢迎订阅!!以下是本期摘要:文章&教程①创下吉尼斯世界记录的Python</div>
                    </li>
                    <li><a href="/article/1880626642808795136.htm"
                           title="Python 潮流周刊#71:PyPI 应该摆脱掉它的赞助依赖(摘要)" target="_blank">Python 潮流周刊#71:PyPI 应该摆脱掉它的赞助依赖(摘要)</a>
                        <span class="text-muted"></span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>本周刊由Python猫出品,精心筛选国内外的250+信息源,为你挑选最值得分享的文章、教程、开源项目、软件工具、播客和视频、热门话题等内容。愿景:帮助所有读者精进Python技术,并增长职业和副业的收入。分享了12篇文章,12个开源项目,1则音视频,全文2000字。以下是本期摘要:文章&教程①PyPI应该摆脱掉它的赞助依赖②创建不分大小写的Python字符串类③用Tree-sitter&Jedi重</div>
                    </li>
                    <li><a href="/article/1880626644146778112.htm"
                           title="Python 潮流周刊#72:Python 3.13.0 最终版已发布!(摘要)" target="_blank">Python 潮流周刊#72:Python 3.13.0 最终版已发布!(摘要)</a>
                        <span class="text-muted"></span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>本周刊由Python猫出品,精心筛选国内外的250+信息源,为你挑选最值得分享的文章、教程、开源项目、软件工具、播客和视频、热门话题等内容。愿景:帮助所有读者精进Python技术,并增长职业和副业的收入。分享了14篇文章,12个开源项目,4则音视频,全文2300字。以下是本期摘要:文章&教程①Python3.13.0最终版已发布!②关于Python3.13,了解这些信息就够了③Python3.13</div>
                    </li>
                    <li><a href="/article/1880626388600418304.htm"
                           title="Python 潮流周刊#67:uv 的重磅更新(摘要)" target="_blank">Python 潮流周刊#67:uv 的重磅更新(摘要)</a>
                        <span class="text-muted"></span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>本周刊由Python猫出品,精心筛选国内外的250+信息源,为你挑选最值得分享的文章、教程、开源项目、软件工具、播客和视频、热门话题等内容。愿景:帮助所有读者精进Python技术,并增长职业和副业的收入。分享了12篇文章,12个开源项目,全文2000字。以下是本期摘要:文章&教程①uv:统一的Python打包工具②PyJWT和python-jose在处理JWT令牌时的差异③Kindle+Pytho</div>
                    </li>
                    <li><a href="/article/1880626389921624064.htm"
                           title="Python 潮流周刊#68:2023 年 Python 开发者调查结果(摘要)" target="_blank">Python 潮流周刊#68:2023 年 Python 开发者调查结果(摘要)</a>
                        <span class="text-muted"></span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>本周刊由Python猫出品,精心筛选国内外的250+信息源,为你挑选最值得分享的文章、教程、开源项目、软件工具、播客和视频、热门话题等内容。愿景:帮助所有读者精进Python技术,并增长职业和副业的收入。分享了12篇文章,12个开源项目,2则热门讨论,全文2100字。以下是本期摘要:文章&教程①2023年Python开发者调查结果②为什么在Docker中我仍然要用Python虚拟环境?③我如何用P</div>
                    </li>
                    <li><a href="/article/1880624597779410944.htm"
                           title="Python WebSocket服务器介绍" target="_blank">Python WebSocket服务器介绍</a>
                        <span class="text-muted">一只会写程序的猫</span>
<a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/websocket/1.htm">websocket</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a>
                        <div>PythonWebSocket服务器介绍WebSocket是一种在Web浏览器和服务器之间实现全双工通信的协议。它允许服务器主动发送消息到浏览器,而不需要浏览器发起请求。Python提供了许多库和框架来实现WebSocket服务器,本文将介绍如何使用Python构建一个简单的WebSocket服务器。WebSocket协议和工作原理WebSocket协议是通过HTTP协议的升级实现的。在HTTP协</div>
                    </li>
                    <li><a href="/article/1880623211608076288.htm"
                           title="python如何读取csv文件?" target="_blank">python如何读取csv文件?</a>
                        <span class="text-muted">gaogsf</span>
<a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>CSV(CommaSeparatedValues)文件是一种常见的文件格式,它将数据以逗号分隔的形式存储,通常用于存储表格数据。在Python中,我们可以使用多种方法来读取CSV文件,本文将从多个角度分析Python如何读取CSV文件。一、Python内置的csv库Python内置了csv库,可以使用该库中的reader对象来读取CSV文件。下面是一个示例代码:importcsvwithopen(</div>
                    </li>
                    <li><a href="/article/1880622203490332672.htm"
                           title="探索装饰器的奥秘:Python里的超级英雄披风" target="_blank">探索装饰器的奥秘:Python里的超级英雄披风</a>
                        <span class="text-muted">大梦百万秋</span>
<a class="tag" taget="_blank" href="/search/%E7%9F%A5%E8%AF%86%E5%AD%A6%E7%88%86/1.htm">知识学爆</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>引言:每一行代码都可以是一件披风有没有想过,代码写得再帅气,读起来再优雅,它始终是千篇一律的套路?有时候,代码中的函数就像是穿着普通衣服的路人,默默地完成任务。而这时候,你可能会想:“嘿,我要给它们一点魔法,让它们更具超能力!”别担心,Python里的装饰器正是你需要的神秘工具,它能给你的函数加上一件“超级英雄披风”,让它们瞬间拥有更多的功能,且不改变它们原本的外貌。今天我们就来一起揭开装饰器的面</div>
                    </li>
                    <li><a href="/article/1880621698949115904.htm"
                           title="在 Python 中使用 PyPDF2 向 PDF 文件批量添加水印" target="_blank">在 Python 中使用 PyPDF2 向 PDF 文件批量添加水印</a>
                        <span class="text-muted">信息科技云课堂</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/pdf/1.htm">pdf</a>
                        <div>目录:使用PyPDF2添加水印到PDF文件批量添加水印到PDF文件所有页PDF文件广泛用于不同的设备和平台上,在某些情况下,可能需要在PDF文件中申明版权,需要将水印、条形码、二维码等添加到PDF中。PyPDF2提供了一种将另一个PDF文件作为水印,添加到PDF文件的方法。在下面的示例中,制作一个PDF水印文档,可以加入文字、二维码,通过合并的方法为PDF文件添加水印。使用PyPDF2添加水印到P</div>
                    </li>
                    <li><a href="/article/1880621475841503232.htm"
                           title="空降中层如何做好管理工作?成功过渡的实用策略" target="_blank">空降中层如何做好管理工作?成功过渡的实用策略</a>
                        <span class="text-muted"></span>
<a class="tag" taget="_blank" href="/search/%E7%A9%BA%E9%99%8D%E4%B8%AD%E5%B1%82%E7%AE%A1%E7%90%86%E5%85%AC%E5%8F%B8%E7%AE%A1%E7%90%86%E5%9B%A2%E9%98%9F%E7%AE%A1%E7%90%86/1.htm">空降中层管理公司管理团队管理</a>
                        <div>空降中层的管理工作充满挑战,既需要迅速适应新环境,又要赢得下属的信任和支持。作为新任的管理者,空降中层不仅要快速理解公司的文化、业务和团队,还要在短时间内建立起有效的领导力和管理体系。做好管理工作可以从以下几个方面着手:快速融入团队、建立信任与沟通、明确目标与期望、优化团队结构、激励与激发团队潜力、以及借助数据与工具进行决策。本文将深入探讨这些管理策略,以帮助空降中层快速适应并实现有效管理。一、快</div>
                    </li>
                    <li><a href="/article/1880621348758286336.htm"
                           title="Python 潮流周刊#86:Jupyter Notebook 智能编码助手(摘要)" target="_blank">Python 潮流周刊#86:Jupyter Notebook 智能编码助手(摘要)</a>
                        <span class="text-muted"></span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>本周刊由Python猫出品,精心筛选国内外的250+信息源,为你挑选最值得分享的文章、教程、开源项目、软件工具、播客和视频、热门话题等内容。愿景:帮助所有读者精进Python技术,并增长职业和副业的收入。分享了12篇文章,12个开源项目,全文2000字。以下是本期摘要:文章&教程①介绍JupyterNotebook智能助手②用纯Python写一个“Redis”,速度比原生Redis还快?③30分钟</div>
                    </li>
                    <li><a href="/article/1880621094310834176.htm"
                           title="Python 中最易误解的功能" target="_blank">Python 中最易误解的功能</a>
                        <span class="text-muted"></span>
<a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a>
                        <div>有些功能即使是经验丰富的开发者也会被难住。我也曾被它们绊倒,花数小时挠头苦思,最终才学会如何正确应对。所以,不浪费时间,让我们来探索Python中最易误解的功能,它们为何棘手,以及你如何能最终掌握它们。1.可变默认参数问题:如果你曾写过一个带有默认列表或字典参数的函数,你可能会注意到一些奇怪的现象。它会在函数调用之间“记住”值!defadd_item(item,items=[]):items.ap</div>
                    </li>
                    <li><a href="/article/1880619178713477120.htm"
                           title="python注册nacos服务" target="_blank">python注册nacos服务</a>
                        <span class="text-muted">MTonj</span>
<a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>根据nacosopenapiOpenAPI指南主要是实现以下接口:创建服务注册实例注销实例删除服务发送实例心跳实现demo如下:一个web服务1http_server1.py#coding:utf-8importsocketfrommultiprocessingimportProcessdefhandle_client(client_socket):"""处理客户端请求"""request_dat</div>
                    </li>
                    <li><a href="/article/1880616404839886848.htm"
                           title="《智守数据堡垒——AI驱动的MySQL数据治理合规框架》" target="_blank">《智守数据堡垒——AI驱动的MySQL数据治理合规框架》</a>
                        <span class="text-muted">墨夶</span>
<a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%992/1.htm">数据库学习资料2</a><a class="tag" taget="_blank" href="/search/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/1.htm">人工智能</a><a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a>
                        <div>在当今数字化转型加速的时代,企业面临着前所未有的数据挑战。一方面,海量的数据为企业带来了巨大的商业价值;另一方面,如何确保这些数据的安全性、一致性和合法性成为了亟待解决的问题。尤其是在金融、医疗等高度监管行业中,任何数据泄露或不当使用都可能导致严重的法律后果和社会影响。为此,构建一个既高效又能满足法律法规要求的数据治理体系显得尤为重要。今天,我们将探讨一种创新性的解决方案——利用人工智能(AI)技</div>
                    </li>
                    <li><a href="/article/1880616407343886336.htm"
                           title="《守护数据隐私的堡垒:构建基于差分隐私的MySQL匿名化处理系统》" target="_blank">《守护数据隐私的堡垒:构建基于差分隐私的MySQL匿名化处理系统》</a>
                        <span class="text-muted">墨夶</span>
<a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%992/1.htm">数据库学习资料2</a><a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a><a class="tag" taget="_blank" href="/search/android/1.htm">android</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a>
                        <div>在大数据时代,个人隐私保护的重要性日益凸显。随着全球范围内对用户信息保护意识的增强以及相关法律法规(如GDPR、CCPA等)的出台,企业面临着前所未有的挑战——如何在利用海量数据创造价值的同时,确保这些数据不会泄露用户的敏感信息。为了应对这一难题,差分隐私(DifferentialPrivacy,DP)作为一种强大的数学工具应运而生。它不仅能够有效地抵御各种形式的重识别攻击,而且还可以保持数据集统</div>
                    </li>
                    <li><a href="/article/1880615142870282240.htm"
                           title="用Python进行websocket接口测试" target="_blank">用Python进行websocket接口测试</a>
                        <span class="text-muted">代码小念</span>
<a class="tag" taget="_blank" href="/search/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/1.htm">软件测试</a><a class="tag" taget="_blank" href="/search/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/1.htm">自动化测试</a><a class="tag" taget="_blank" href="/search/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/1.htm">技术分享</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/websocket/1.htm">websocket</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>这篇文章主要介绍了用Python进行websocket接口测试,帮助大家更好的理解和使用python,感兴趣的朋友可以了解下我们在做接口测试时,除了常见的http接口,还有一种比较多见,就是socket接口,今天讲解下怎么用Python进行websocket接口测试。SocketSocket又称"套接字",应用程序通常通过"套接字"向网络发出请求或者应答网络请求,使主机间或者一台计算机上的进程间可</div>
                    </li>
                    <li><a href="/article/1880614004649422848.htm"
                           title="Next.js服务器操作:优势、局限与审慎应用" target="_blank">Next.js服务器操作:优势、局限与审慎应用</a>
                        <span class="text-muted">exploration-earth</span>
<a class="tag" taget="_blank" href="/search/javascript/1.htm">javascript</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>类似于任何技术,它们亦非尽善尽美,故而保持警觉至关重要。通过亲身经历中的挫折汲取了教训,现将之与诸位共勉。一大诟病在于潜在的紧密绑定问题。若服务器端代码嵌入组件之中,则可能导致代码库模块化程度削弱,维护成本攀升。后端逻辑的任何变动或许都将迫使前端相应更新,反之亦然。对于追求关注点严格分离的大型项目或团队而言,这无疑构成了严峻挑战。唯有秉持严谨的纪律与条理,方能避免代码库陷入混乱。再者,便是学习曲线</div>
                    </li>
                    <li><a href="/article/1880611855605493760.htm"
                           title="使用 Python 实现 WebSocket 服务器与客户端通信" target="_blank">使用 Python 实现 WebSocket 服务器与客户端通信</a>
                        <span class="text-muted">又蓝</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/websocket/1.htm">websocket</a>
                        <div>简介WebSocket是一种基于TCP协议的通信协议,能够在客户端与服务器之间进行全双工(双向)通信。相比传统的HTTP协议,WebSocket可以实现实时数据的传输,尤其适合需要实时交互的应用场景,如在线游戏、实时聊天、金融交易等。我通过Python实现一个简单的WebSocket服务器,并使其与客户端进行通信。我们将创建两个Python文件:websocket.py和main.py,webso</div>
                    </li>
                    <li><a href="/article/1880607822786392064.htm"
                           title="基于Python实现读取嵌套压缩包下的文件" target="_blank">基于Python实现读取嵌套压缩包下的文件</a>
                        <span class="text-muted">袁袁袁袁满</span>
<a class="tag" taget="_blank" href="/search/Python%E5%AE%9E%E7%94%A8%E6%8A%80%E5%B7%A7%E5%A4%A7%E5%85%A8/1.htm">Python实用技巧大全</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%B5%8C%E5%A5%97%E5%8E%8B%E7%BC%A9%E5%8C%85%E4%B8%8B%E6%96%87%E4%BB%B6%E8%AF%BB%E5%8F%96/1.htm">嵌套压缩包下文件读取</a><a class="tag" taget="_blank" href="/search/Python%E5%AE%9E%E7%8E%B0%E5%B5%8C%E5%A5%97%E5%8E%8B%E7%BC%A9%E5%8C%85/1.htm">Python实现嵌套压缩包</a><a class="tag" taget="_blank" href="/search/%E5%8E%8B%E7%BC%A9%E5%8C%85/1.htm">压缩包</a><a class="tag" taget="_blank" href="/search/zipfile/1.htm">zipfile</a><a class="tag" taget="_blank" href="/search/BytesIO/1.htm">BytesIO</a>
                        <div>文章目录前言思路完整代码代码优化前言工作中遇到的问题,需要用Python实现嵌套压缩包下文件读取,这里记录下方法,希望能帮助到更多的人。思路打开外层zip压缩包并遍历文件:使用withzipfile.ZipFile(outer_zip_path,'r')asouter_zip语句以读取模式'r'打开用户输入的外层zip压缩包对应的文件,这样在代码块结束后会自动关闭该文件,避免资源泄露。通过oute</div>
                    </li>
                    <li><a href="/article/1880607696642699264.htm"
                           title="【如何利用Python抢演唱会门票】python利用selenium实现大麦网抢票" target="_blank">【如何利用Python抢演唱会门票】python利用selenium实现大麦网抢票</a>
                        <span class="text-muted">Python小炮车</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/selenium/1.htm">selenium</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a>
                        <div>一、selenium原理介绍Selenium是一个用于Web[应用程序](https://link.juejin.cn/?target=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E5%25BA%2594%25E7%2594%25A8%25E7%25A8%258B%25E5%25BA%258F%2F5985445%3FfromModule%3Dlemma_i</div>
                    </li>
                    <li><a href="/article/1880602145523298304.htm"
                           title="Python 实现七大排序算法" target="_blank">Python 实现七大排序算法</a>
                        <span class="text-muted">weixin_30527323</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/shell/1.htm">shell</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/1.htm">数据结构与算法</a>
                        <div>技术博客:github.com/yongxinz/te…本文用Python实现了插入排序、希尔排序、冒泡排序、快速排序、直接选择排序、堆排序、归并排序。先整体看一下各个算法之间的对比,然后再进行详细介绍:排序算法平均时间复杂度最好情况最坏情况空间复杂度排序方式稳定性插入排序O(n²)O(n)O(n²)O(1)In-place稳定冒泡排序O(n²)O(n)O(n²)O(1)In-place稳定选择排</div>
                    </li>
                    <li><a href="/article/1880597101025488896.htm"
                           title="Python数据分析高频面试题及答案" target="_blank">Python数据分析高频面试题及答案</a>
                        <span class="text-muted">闲人编程</span>
<a class="tag" taget="_blank" href="/search/%E7%A8%8B%E5%BA%8F%E5%91%98%E9%9D%A2%E8%AF%95/1.htm">程序员面试</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95%E9%A2%98/1.htm">面试题</a><a class="tag" taget="_blank" href="/search/%E6%A0%B8%E5%BF%83/1.htm">核心</a>
                        <div>目录1.基础知识2.数据处理3.数据可视化4.机器学习模型5.进阶问题6.数据清洗与预处理7.数据转换与操作8.时间序列分析9.高级数据分析技术10.数据降维与特征选择11.模型评估与优化12.数据操作与转换13.数据筛选与分析14.数据可视化与报告15.数据统计与分析16.高级数据处理以下是一些Python数据分析的高频核心面试题及其答案,涵盖了基础知识、数据1.基础知识问1:Python中列表</div>
                    </li>
                    <li><a href="/article/1880593054130302976.htm"
                           title="Python数据分析常见面试题和答案01-10" target="_blank">Python数据分析常见面试题和答案01-10</a>
                        <span class="text-muted">飞翔还哈哈6</span>
<a class="tag" taget="_blank" href="/search/Python%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">Python数据分析</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/pandas/1.htm">pandas</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a>
                        <div>以下是一些Python数据分析常见面试题和答案:1.Python中的list和tuple的区别是什么?答:List是可变的,而元组(tuple)是不可变的。因此,使用list来存储需要频繁修改的数据,而使用元组来存储不能更改的数据项。2.解释NumPy中的数组?为什么numpy在数据分析中很重要?答:NumPy是Python中提供高性能科学计算和数据分析的包。NumPy数组是一种类似于列表的数据结</div>
                    </li>
                    <li><a href="/article/1880592927818838016.htm"
                           title="【Python小技巧】使用prettytable格式化显示dataframe数据" target="_blank">【Python小技巧】使用prettytable格式化显示dataframe数据</a>
                        <span class="text-muted">IT里的交易员</span>
<a class="tag" taget="_blank" href="/search/Python%E7%BB%8F%E9%AA%8C%E6%B1%A0/1.htm">Python经验池</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>文章目录前言一、安装prettytable二、函数打包三、应用示例总结前言经常我们使用print(df)输出dataframe数据,打印输出的数据没有格式,看起来屏幕一篇乱。有没有一种可以格式化输出的工具?还真有,那就是prettytable。一、安装prettytablePrettyTable是Python中的一个库,用于以美观的表格形式显示数据。要使用PrettyTable,首先需要安装它,可</div>
                    </li>
                    <li><a href="/article/1880591789530869760.htm"
                           title="keepalived+haproxy实现高可用集群" target="_blank">keepalived+haproxy实现高可用集群</a>
                        <span class="text-muted">mark.meng</span>
<a class="tag" taget="_blank" href="/search/%E4%B8%AD%E9%97%B4%E4%BB%B6/1.htm">中间件</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a>
                        <div>实验环境172.16.32.21172.16.32.22Vip:172.16.32.301.部署httpd测试服务yuminstallhttpdecho"172.16.32.22">>/var/www/html/id.htmlsystemctlstarthttpdcurl172.16.32.22/id.html172.16.32.222.部署haproxy实现负载均衡yuminstallhapro</div>
                    </li>
                                <li><a href="/article/125.htm"
                                       title="apache 安装linux windows" target="_blank">apache 安装linux windows</a>
                                    <span class="text-muted">墙头上一根草</span>
<a class="tag" taget="_blank" href="/search/apache/1.htm">apache</a><a class="tag" taget="_blank" href="/search/inux/1.htm">inux</a><a class="tag" taget="_blank" href="/search/windows/1.htm">windows</a>
                                    <div>linux安装Apache 有两种方式一种是手动安装通过二进制的文件进行安装,另外一种就是通过yum 安装,此中安装方式,需要物理机联网。以下分别介绍两种的安装方式 
  
  
通过二进制文件安装Apache需要的软件有apr,apr-util,pcre 
 1,安装 apr        下载地址:htt</div>
                                </li>
                                <li><a href="/article/252.htm"
                                       title="fill_parent、wrap_content和match_parent的区别" target="_blank">fill_parent、wrap_content和match_parent的区别</a>
                                    <span class="text-muted">Cb123456</span>
<a class="tag" taget="_blank" href="/search/match_parent/1.htm">match_parent</a><a class="tag" taget="_blank" href="/search/fill_parent/1.htm">fill_parent</a>
                                    <div>fill_parent、wrap_content和match_parent的区别: 
  
1)fill_parent 
  设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。这跟Windows控件的dockstyle属性大体一致。设置一个顶部布局或控件为fill_parent将强制性让它布满整个屏幕。 
2) wrap_conte</div>
                                </li>
                                <li><a href="/article/379.htm"
                                       title="网页自适应设计" target="_blank">网页自适应设计</a>
                                    <span class="text-muted">天子之骄</span>
<a class="tag" taget="_blank" href="/search/html/1.htm">html</a><a class="tag" taget="_blank" href="/search/css/1.htm">css</a><a class="tag" taget="_blank" href="/search/%E5%93%8D%E5%BA%94%E5%BC%8F%E8%AE%BE%E8%AE%A1/1.htm">响应式设计</a><a class="tag" taget="_blank" href="/search/%E9%A1%B5%E9%9D%A2%E8%87%AA%E9%80%82%E5%BA%94/1.htm">页面自适应</a>
                                    <div>网页自适应设计 
       网页对浏览器窗口的自适应支持变得越来越重要了。自适应响应设计更是异常火爆。再加上移动端的崛起,更是如日中天。以前为了适应不同屏幕分布率和浏览器窗口的扩大和缩小,需要设计几套css样式,用js脚本判断窗口大小,选择加载。结构臃肿,加载负担较大。现笔者经过一定时间的学习,有所心得,故分享于此,加强交流,共同进步。同时希望对大家有所</div>
                                </li>
                                <li><a href="/article/506.htm"
                                       title="[sql server] 分组取最大最小常用sql" target="_blank">[sql server] 分组取最大最小常用sql</a>
                                    <span class="text-muted">一炮送你回车库</span>
<a class="tag" taget="_blank" href="/search/SQL+Server/1.htm">SQL Server</a>
                                    <div>--分组取最大最小常用sql--测试环境if OBJECT_ID('tb') is not null drop table tb;gocreate table tb( col1 int, col2 int, Fcount int)insert into tbselect 11,20,1 union allselect 11,22,1 union allselect 1</div>
                                </li>
                                <li><a href="/article/633.htm"
                                       title="ImageIO写图片输出到硬盘" target="_blank">ImageIO写图片输出到硬盘</a>
                                    <span class="text-muted">3213213333332132</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/image/1.htm">image</a>
                                    <div>package awt; 
 
import java.awt.Color; 
import java.awt.Font; 
import java.awt.Graphics; 
import java.awt.image.BufferedImage; 
import java.io.File; 
import java.io.IOException; 
 
import javax.imagei</div>
                                </li>
                                <li><a href="/article/760.htm"
                                       title="自己的String动态数组" target="_blank">自己的String动态数组</a>
                                    <span class="text-muted">宝剑锋梅花香</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%8A%A8%E6%80%81%E6%95%B0%E7%BB%84/1.htm">动态数组</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E7%BB%84/1.htm">数组</a>
                                    <div>数组还是好说,学过一两门编程语言的就知道,需要注意的是数组声明时需要把大小给它定下来,比如声明一个字符串类型的数组:String str[]=new String[10];    但是问题就来了,每次都是大小确定的数组,我需要数组大小不固定随时变化怎么办呢?  动态数组就这样应运而生,龙哥给我们讲的是自己用代码写动态数组,并非用的ArrayList 看看字符</div>
                                </li>
                                <li><a href="/article/887.htm"
                                       title="pinyin4j工具类" target="_blank">pinyin4j工具类</a>
                                    <span class="text-muted">darkranger</span>
<a class="tag" taget="_blank" href="/search/.net/1.htm">.net</a>
                                    <div>pinyin4j工具类Java工具类 2010-04-24 00:47:00 阅读69 评论0 字号:大中小 
引入pinyin4j-2.5.0.jar包: 
pinyin4j是一个功能强悍的汉语拼音工具包,主要是从汉语获取各种格式和需求的拼音,功能强悍,下面看看如何使用pinyin4j。 
 
本人以前用AscII编码提取工具,效果不理想,现在用pinyin4j简单实现了一个。功能还不是很完美,</div>
                                </li>
                                <li><a href="/article/1014.htm"
                                       title="StarUML学习笔记----基本概念" target="_blank">StarUML学习笔记----基本概念</a>
                                    <span class="text-muted">aijuans</span>
<a class="tag" taget="_blank" href="/search/UML%E5%BB%BA%E6%A8%A1/1.htm">UML建模</a>
                                    <div>介绍StarUML的基本概念,这些都是有效运用StarUML?所需要的。包括对模型、视图、图、项目、单元、方法、框架、模型块及其差异以及UML轮廓。 
        模型、视与图(Model, View and Diagram) 
       &</div>
                                </li>
                                <li><a href="/article/1141.htm"
                                       title="Activiti最终总结" target="_blank">Activiti最终总结</a>
                                    <span class="text-muted">avords</span>
<a class="tag" taget="_blank" href="/search/Activiti+id+%E5%B7%A5%E4%BD%9C%E6%B5%81/1.htm">Activiti id 工作流</a>
                                    <div>1、流程定义ID:ProcessDefinitionId,当定义一个流程就会产生。 
2、流程实例ID:ProcessInstanceId,当开始一个具体的流程时就会产生,也就是不同的流程实例ID可能有相同的流程定义ID。 
3、TaskId,每一个userTask都会有一个Id这个是存在于流程实例上的。 
4、TaskDefinitionKey和(ActivityImpl activityId </div>
                                </li>
                                <li><a href="/article/1268.htm"
                                       title="从省市区多重级联想到的,react和jquery的差别" target="_blank">从省市区多重级联想到的,react和jquery的差别</a>
                                    <span class="text-muted">bee1314</span>
<a class="tag" taget="_blank" href="/search/jquery/1.htm">jquery</a><a class="tag" taget="_blank" href="/search/UI/1.htm">UI</a><a class="tag" taget="_blank" href="/search/react/1.htm">react</a>
                                    <div>在我们的前端项目里经常会用到级联的select,比如省市区这样。通常这种级联大多是动态的。比如先加载了省,点击省加载市,点击市加载区。然后数据通常ajax返回。如果没有数据则说明到了叶子节点。       针对这种场景,如果我们使用jquery来实现,要考虑很多的问题,数据部分,以及大量的dom操作。比如这个页面上显示了某个区,这时候我切换省,要把市重新初始化数据,然后区域的部分要从页面</div>
                                </li>
                                <li><a href="/article/1395.htm"
                                       title="Eclipse快捷键大全" target="_blank">Eclipse快捷键大全</a>
                                    <span class="text-muted">bijian1013</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/eclipse/1.htm">eclipse</a><a class="tag" taget="_blank" href="/search/%E5%BF%AB%E6%8D%B7%E9%94%AE/1.htm">快捷键</a>
                                    <div>Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加)Ctrl+Alt+↑ 复制当前行到上一行(复制增加)Alt+↓ 当前行和下面一行交互位置(特别实用,可以省去先剪切,再粘贴了)Alt+↑ 当前行和上面一行交互位置(同上)Alt+← 前一个编辑的页面Alt+→ 下一个编辑的页面(当然是针对上面那条来说了)Alt+En</div>
                                </li>
                                <li><a href="/article/1522.htm"
                                       title="js 笔记 函数" target="_blank">js 笔记 函数</a>
                                    <span class="text-muted">征客丶</span>
<a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a>
                                    <div>一、函数的使用 
1.1、定义函数变量 
var vName = funcation(params){ 
} 
 
1.2、函数的调用 
函数变量的调用:      vName(params); 
函数定义时自发调用:(function(params){})(params); 
 
1.3、函数中变量赋值 
var a = 'a'; 
var ff</div>
                                </li>
                                <li><a href="/article/1649.htm"
                                       title="【Scala四】分析Spark源代码总结的Scala语法二" target="_blank">【Scala四】分析Spark源代码总结的Scala语法二</a>
                                    <span class="text-muted">bit1129</span>
<a class="tag" taget="_blank" href="/search/scala/1.htm">scala</a>
                                    <div>1. Some操作 
  
在下面的代码中,使用了Some操作:if (self.partitioner == Some(partitioner)),那么Some(partitioner)表示什么含义?首先partitioner是方法combineByKey传入的变量, 
Some的文档说明: 
  
/** Class `Some[A]` represents existin</div>
                                </li>
                                <li><a href="/article/1776.htm"
                                       title="java 匿名内部类" target="_blank">java 匿名内部类</a>
                                    <span class="text-muted">BlueSkator</span>
<a class="tag" taget="_blank" href="/search/java%E5%8C%BF%E5%90%8D%E5%86%85%E9%83%A8%E7%B1%BB/1.htm">java匿名内部类</a>
                                    <div>组合优先于继承 
Java的匿名类,就是提供了一个快捷方便的手段,令继承关系可以方便地变成组合关系 
继承只有一个时候才能用,当你要求子类的实例可以替代父类实例的位置时才可以用继承。 
  
在Java中内部类主要分为成员内部类、局部内部类、匿名内部类、静态内部类。 
内部类不是很好理解,但说白了其实也就是一个类中还包含着另外一个类如同一个人是由大脑、肢体、器官等身体结果组成,而内部类相</div>
                                </li>
                                <li><a href="/article/1903.htm"
                                       title="盗版win装在MAC有害发热,苹果的东西不值得买,win应该不用" target="_blank">盗版win装在MAC有害发热,苹果的东西不值得买,win应该不用</a>
                                    <span class="text-muted">ljy325</span>
<a class="tag" taget="_blank" href="/search/%E6%B8%B8%E6%88%8F/1.htm">游戏</a><a class="tag" taget="_blank" href="/search/apple/1.htm">apple</a><a class="tag" taget="_blank" href="/search/windows/1.htm">windows</a><a class="tag" taget="_blank" href="/search/XP/1.htm">XP</a><a class="tag" taget="_blank" href="/search/OS/1.htm">OS</a>
                                    <div>Mac mini 型号: MC270CH-A RMB:5,688 
  
Apple 对windows的产品支持不好,有以下问题: 
  
1.装完了xp,发现机身很热虽然没有运行任何程序!貌似显卡跑游戏发热一样,按照那样的发热量,那部机子损耗很大,使用寿命受到严重的影响! 
  
2.反观安装了Mac os的展示机,发热量很小,运行了1天温度也没有那么高 
&nbs</div>
                                </li>
                                <li><a href="/article/2030.htm"
                                       title="读《研磨设计模式》-代码笔记-生成器模式-Builder" target="_blank">读《研磨设计模式》-代码笔记-生成器模式-Builder</a>
                                    <span class="text-muted">bylijinnan</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/1.htm">设计模式</a>
                                    <div>声明: 本文只为方便我个人查阅和理解,详细的分析以及源代码请移步 原作者的博客http://chjavach.iteye.com/ 
 
 



/**
 * 生成器模式的意图在于将一个复杂的构建与其表示相分离,使得同样的构建过程可以创建不同的表示(GoF)
 * 个人理解:
 * 构建一个复杂的对象,对于创建者(Builder)来说,一是要有数据来源(rawData),二是要返回构</div>
                                </li>
                                <li><a href="/article/2157.htm"
                                       title="JIRA与SVN插件安装" target="_blank">JIRA与SVN插件安装</a>
                                    <span class="text-muted">chenyu19891124</span>
<a class="tag" taget="_blank" href="/search/SVN/1.htm">SVN</a><a class="tag" taget="_blank" href="/search/jira/1.htm">jira</a>
                                    <div>JIRA安装好后提交代码并要显示在JIRA上,这得需要用SVN的插件才能看见开发人员提交的代码。 
1.下载svn与jira插件安装包,解压后在安装包(atlassian-jira-subversion-plugin-0.10.1) 
2.解压出来的包里下的lib文件夹下的jar拷贝到(C:\Program Files\Atlassian\JIRA 4.3.4\atlassian-jira\WEB</div>
                                </li>
                                <li><a href="/article/2284.htm"
                                       title="常用数学思想方法" target="_blank">常用数学思想方法</a>
                                    <span class="text-muted">comsci</span>
<a class="tag" taget="_blank" href="/search/%E5%B7%A5%E4%BD%9C/1.htm">工作</a>
                                    <div>  对于搞工程和技术的朋友来讲,在工作中常常遇到一些实际问题,而采用常规的思维方式无法很好的解决这些问题,那么这个时候我们就需要用数学语言和数学工具,而使用数学工具的前提却是用数学思想的方法来描述问题。。下面转帖几种常用的数学思想方法,仅供学习和参考 
 
 
 
  函数思想 
  把某一数学问题用函数表示出来,并且利用函数探究这个问题的一般规律。这是最基本、最常用的数学方法</div>
                                </li>
                                <li><a href="/article/2411.htm"
                                       title="pl/sql集合类型" target="_blank">pl/sql集合类型</a>
                                    <span class="text-muted">daizj</span>
<a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a><a class="tag" taget="_blank" href="/search/%E9%9B%86%E5%90%88/1.htm">集合</a><a class="tag" taget="_blank" href="/search/type/1.htm">type</a><a class="tag" taget="_blank" href="/search/pl%2Fsql/1.htm">pl/sql</a>
                                    <div>--集合类型 
/* 
  单行单列的数据,使用标量变量 
  单行多列数据,使用记录 
  单列多行数据,使用集合(。。。) 
  *集合:类似于数组也就是。pl/sql集合类型包括索引表(pl/sql table)、嵌套表(Nested Table)、变长数组(VARRAY)等 
*/ 
/* 
    --集合方法 
&n</div>
                                </li>
                                <li><a href="/article/2538.htm"
                                       title="[Ofbiz]ofbiz初用" target="_blank">[Ofbiz]ofbiz初用</a>
                                    <span class="text-muted">dinguangx</span>
<a class="tag" taget="_blank" href="/search/%E7%94%B5%E5%95%86/1.htm">电商</a><a class="tag" taget="_blank" href="/search/ofbiz/1.htm">ofbiz</a>
                                    <div>从github下载最新的ofbiz(截止2015-7-13),从源码进行ofbiz的试用 
1. 加载测试库 
ofbiz内置derby,通过下面的命令初始化测试库 
./ant load-demo (与load-seed有一些区别) 
  
2. 启动内置tomcat 
./ant start 
或 
./startofbiz.sh 
或 
java -jar ofbiz.jar 
&</div>
                                </li>
                                <li><a href="/article/2665.htm"
                                       title="结构体中最后一个元素是长度为0的数组" target="_blank">结构体中最后一个元素是长度为0的数组</a>
                                    <span class="text-muted">dcj3sjt126com</span>
<a class="tag" taget="_blank" href="/search/c/1.htm">c</a><a class="tag" taget="_blank" href="/search/gcc/1.htm">gcc</a>
                                    <div>在Linux源代码中,有很多的结构体最后都定义了一个元素个数为0个的数组,如/usr/include/linux/if_pppox.h中有这样一个结构体: struct pppoe_tag {     __u16 tag_type;     __u16 tag_len;   &n</div>
                                </li>
                                <li><a href="/article/2792.htm"
                                       title="Linux cp 实现强行覆盖" target="_blank">Linux cp 实现强行覆盖</a>
                                    <span class="text-muted">dcj3sjt126com</span>
<a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a>
                                    <div>发现在Fedora 10 /ubutun 里面用cp -fr src dest,即使加了-f也是不能强行覆盖的,这时怎么回事的呢?一两个文件还好说,就输几个yes吧,但是要是n多文件怎么办,那还不输死人呢?下面提供三种解决办法。 方法一 
 
 我们输入alias命令,看看系统给cp起了一个什么别名。 
  
  [root@localhost ~]# aliasalias cp=’cp -i’a</div>
                                </li>
                                <li><a href="/article/2919.htm"
                                       title="Memcached(一)、HelloWorld" target="_blank">Memcached(一)、HelloWorld</a>
                                    <span class="text-muted">frank1234</span>
<a class="tag" taget="_blank" href="/search/memcached/1.htm">memcached</a>
                                    <div>一、简介 
高性能的架构离不开缓存,分布式缓存中的佼佼者当属memcached,它通过客户端将不同的key hash到不同的memcached服务器中,而获取的时候也到相同的服务器中获取,由于不需要做集群同步,也就省去了集群间同步的开销和延迟,所以它相对于ehcache等缓存来说能更好的支持分布式应用,具有更强的横向伸缩能力。 
二、客户端 
选择一个memcached客户端,我这里用的是memc</div>
                                </li>
                                <li><a href="/article/3046.htm"
                                       title="Search in Rotated Sorted Array II" target="_blank">Search in Rotated Sorted Array II</a>
                                    <span class="text-muted">hcx2013</span>
<a class="tag" taget="_blank" href="/search/search/1.htm">search</a>
                                    <div>Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? 
Would this affect the run-time complexity? How and why? 
Write a function to determine if a given ta</div>
                                </li>
                                <li><a href="/article/3173.htm"
                                       title="Spring4新特性——更好的Java泛型操作API" target="_blank">Spring4新特性——更好的Java泛型操作API</a>
                                    <span class="text-muted">jinnianshilongnian</span>
<a class="tag" taget="_blank" href="/search/spring4/1.htm">spring4</a><a class="tag" taget="_blank" href="/search/generic+type/1.htm">generic type</a>
                                    <div>Spring4新特性——泛型限定式依赖注入 
Spring4新特性——核心容器的其他改进 
Spring4新特性——Web开发的增强 
Spring4新特性——集成Bean Validation 1.1(JSR-349)到SpringMVC  
Spring4新特性——Groovy Bean定义DSL 
Spring4新特性——更好的Java泛型操作API  
Spring4新</div>
                                </li>
                                <li><a href="/article/3300.htm"
                                       title="CentOS安装JDK" target="_blank">CentOS安装JDK</a>
                                    <span class="text-muted">liuxingguome</span>
<a class="tag" taget="_blank" href="/search/centos/1.htm">centos</a>
                                    <div>1、行卸载原来的: 
[root@localhost opt]# rpm -qa | grep java 
tzdata-java-2014g-1.el6.noarch 
java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el6_5.x86_64 
java-1.6.0-openjdk-1.6.0.0-11.1.13.4.el6.x86_64 
[root@localhost</div>
                                </li>
                                <li><a href="/article/3427.htm"
                                       title="二分搜索专题2-在有序二维数组中搜索一个元素" target="_blank">二分搜索专题2-在有序二维数组中搜索一个元素</a>
                                    <span class="text-muted">OpenMind</span>
<a class="tag" taget="_blank" href="/search/%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84/1.htm">二维数组</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a><a class="tag" taget="_blank" href="/search/%E4%BA%8C%E5%88%86%E6%90%9C%E7%B4%A2/1.htm">二分搜索</a>
                                    <div>1,设二维数组p的每行每列都按照下标递增的顺序递增。 
用数学语言描述如下:p满足 
(1),对任意的x1,x2,y,如果x1<x2,则p(x1,y)<p(x2,y); 
(2),对任意的x,y1,y2, 如果y1<y2,则p(x,y1)<p(x,y2); 
2,问题: 
给定满足1的数组p和一个整数k,求是否存在x0,y0使得p(x0,y0)=k? 
3,算法分析: 
(</div>
                                </li>
                                <li><a href="/article/3554.htm"
                                       title="java 随机数 Math与Random" target="_blank">java 随机数 Math与Random</a>
                                    <span class="text-muted">SaraWon</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/Math/1.htm">Math</a><a class="tag" taget="_blank" href="/search/Random/1.htm">Random</a>
                                    <div>今天需要在程序中产生随机数,知道有两种方法可以使用,但是使用Math和Random的区别还不是特别清楚,看到一篇文章是关于的,觉得写的还挺不错的,原文地址是 
http://www.oschina.net/question/157182_45274?sort=default&p=1#answers 
 
产生1到10之间的随机数的两种实现方式: 
 

//Math
Math.roun</div>
                                </li>
                                <li><a href="/article/3681.htm"
                                       title="oracle创建表空间" target="_blank">oracle创建表空间</a>
                                    <span class="text-muted">tugn</span>
<a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a>
                                    <div>create temporary tablespace TXSJ_TEMP   
tempfile 'E:\Oracle\oradata\TXSJ_TEMP.dbf'   
size 32m   
autoextend on   
next 32m maxsize 2048m   
extent m</div>
                                </li>
                                <li><a href="/article/3808.htm"
                                       title="使用Java8实现自己的个性化搜索引擎" target="_blank">使用Java8实现自己的个性化搜索引擎</a>
                                    <span class="text-muted">yangshangchuan</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/superword/1.htm">superword</a><a class="tag" taget="_blank" href="/search/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E/1.htm">搜索引擎</a><a class="tag" taget="_blank" href="/search/java8/1.htm">java8</a><a class="tag" taget="_blank" href="/search/%E5%85%A8%E6%96%87%E6%A3%80%E7%B4%A2/1.htm">全文检索</a>
                                    <div>需要对249本软件著作实现句子级别全文检索,这些著作均为PDF文件,不使用现有的框架如lucene,自己实现的方法如下: 
1、从PDF文件中提取文本,这里的重点是如何最大可能地还原文本。提取之后的文本,一个句子一行保存为文本文件。 
2、将所有文本文件合并为一个单一的文本文件,这样,每一个句子就有一个唯一行号。 
3、对每一行文本进行分词,建立倒排表,倒排表的格式为:词=包含该词的总行数N=行号</div>
                                </li>
                </ul>
            </div>
        </div>
    </div>

<div>
    <div class="container">
        <div class="indexes">
            <strong>按字母分类:</strong>
            <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a
                href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a
                href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a
                href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a
                href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a
                href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a
                href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a
                href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a
                href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a>
        </div>
    </div>
</div>
<footer id="footer" class="mb30 mt30">
    <div class="container">
        <div class="footBglm">
            <a target="_blank" href="/">首页</a> -
            <a target="_blank" href="/custom/about.htm">关于我们</a> -
            <a target="_blank" href="/search/Java/1.htm">站内搜索</a> -
            <a target="_blank" href="/sitemap.txt">Sitemap</a> -
            <a target="_blank" href="/custom/delete.htm">侵权投诉</a>
        </div>
        <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved.
<!--            <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>-->
        </div>
    </div>
</footer>
<!-- 代码高亮 -->
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script>
<link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/>
<script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script>





</body>

</html>