Python数据分析之numpy数组全解析
<h1 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">1 什么是numpy</h1><p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">numpy是一个在Python中做科学计算的基础库,重在数值计算,也是大部分Python科学计算库的基础库,多用于大型、多维数据上执行数值计算。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">在NumPy 中,最重要的对象是称为 ndarray 的N维数组类型,它是描述相同类型的元素集合,numpy所有功能几乎都以ndarray为核心展开。ndarray 中的每个元素都是数据类型对象(dtype)的对象。ndarray 中的每个元素在内存中使用相同大小的块</p>
<h1 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">2 numpy数组创建</h1>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">创建Numpy数组一般有三种方法:</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">(1)通过传入可待跌对象创建,我将之称为基本方法</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">(2)使用Numpy内部功能函数,内部方法</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">(3)使用特殊的库函数,特殊方法</p>
<h2 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">2.1 基本方法:np.array()</h2>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">基本方法是通过给numpy提供的一些函数中传入可迭代对象来创建数组,这种方法通常是在已知所有元素的情况下使用。numpy中实现这种功能的函数包括:np.array()、np.arange()、np.line(),:</p>
<div class="cnblogs_code">
<pre>>>> np.array() <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 接收一个list作为参数</span>
array()
</span>>>> np.array([,]) <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 创建一个2*3的数组</span>
array([,
[</span>21, 22, 23<span style="color: rgba(0, 0, 0, 1)">]])
</span>>>> np.array((0, 1, 2, 3, 4)) <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 接收一个tuple作为参数</span>
array()
np.array()方法可以在创建数组的同时指定数据类型:
</span>>>> np.array(, dtype=<span style="color: rgba(0, 0, 0, 1)">float)
array()</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">甚至还可以接受range()返回的可迭代对象作为参数:</p>
<div class="cnblogs_code">
<pre>>>> np.array(range(5<span style="color: rgba(0, 0, 0, 1)">))
array()
</span>>>> np.array(range(10, 20, 2<span style="color: rgba(0, 0, 0, 1)">))
array([</span>10, 12, 14, 16, 18])</pre>
</div>
<h2 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">2.2 通用方法:np.ones()、np.zeros()、np.eye()</h2>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">通用方法指的是numpy中提供的arange()、ones()、zeros()、eye()、full()等方法,这些方法可以按照某种规则生成一个数组,并不需要传入已知的可迭代对象。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(1)np.arange()</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">上面我们将range()函数结果传递给np.array(),np.arange()实现的就是这个功能,所以说,np.arange()就是numpy中的range()方法。</p>
<div class="cnblogs_code">
<pre>>>> np.arange(5<span style="color: rgba(0, 0, 0, 1)">)
array()
</span>>>> np.arange(10, 20, 2<span style="color: rgba(0, 0, 0, 1)">)
array([</span>10, 12, 14, 16, 18])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(2)np.linspace()</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">np.linspace()方法以等间距的形式对给定的两数进行划分来创建数组:</p>
<div class="cnblogs_code">
<pre>>>> np.linspace(10, 20, 5) <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 将10到20间的数等距取5个</span>
array()</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(3)np.ones()</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">创建一个元素值全为1的数组,接收一个list或者tuple作为参数</p>
<div class="cnblogs_code">
<pre>>>> np.ones() <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 创建一个一维数组</span>
array()
</span>>>> np.ones() <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 创建一个2维数组</span>
array([,
[</span>1., 1<span style="color: rgba(0, 0, 0, 1)">.]])
</span>>>> np.ones()
array([[[</span>1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1<span style="color: rgba(0, 0, 0, 1)">.]],
[[</span>1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1.]]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(4)np.zeros()</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">创建一个元素值全为0的数组,接收一个list或者tuple作为参数</p>
<div class="cnblogs_code">
<pre>>>> np.zeros()
array()
</span>>>> np.zeros()
array([,
,
])</span></pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(5)np.random.random()</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">创建一个元素为0到1之间随机数的数组,接收一个list或者tuple作为参数:</p>
<div class="cnblogs_code">
<pre>>>> np.random.random((3, 3<span style="color: rgba(0, 0, 0, 1)">))
array([[</span>0.19414645, 0.2306415 , 0.08072019<span style="color: rgba(0, 0, 0, 1)">],
[</span>0.68814308, 0.48019088, 0.61438206<span style="color: rgba(0, 0, 0, 1)">],
[</span>0.5361477 , 0.33779769, 0.38549407]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">既然有random()方法,那么就会有randint()方法,也就是取随机整数的方法,不过这个randint()方法参数形式更random()不太一样,具体请看下面实例:</p>
<div class="cnblogs_code">
<pre>>>> np.random.randint(1, 10, 3) <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 从1到10之间随机取3个整数创建数组</span>
array()</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(6)np.eye()</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">创建一个从左上角到右下角的对角线上全为1,其余元素全为0的数组(单位矩阵)。注意,np.eye()的参数可不再是list或者tuple了。</p>
<div class="cnblogs_code">
<pre>>>> np.eye(3, 3<span style="color: rgba(0, 0, 0, 1)">)
array([[</span>1<span style="color: rgba(0, 0, 0, 1)">., 0., 0.],
,
])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(7) np.full()</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">np.full()函数可以创建一个填充给定数值的数组,第一个参数是定义数组形状的list或tuple,第2个参数是需要填充的数值:</p>
<div class="cnblogs_code">
<pre>>>> np.full((2, 3), 3) <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 创建一个2*3的数组,所有元素都填充3</span>
array([,
[</span>3, 3, 3]])</pre>
</div>
<h2 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">2.3 读取外部数据</h2>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">numpy也支持从外部读取数据来创建数组,例如从硬盘中读取csv、txt等文件来创建数组。np.genfromtxt()是numpy中读取文件的一个方法,例如在当前目录下有一个data.csv文件,文件内容为:</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">id,height,length</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">1,100,101</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">2,200,230</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">3,300,350</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">通过numpy读取:</p>
<div class="cnblogs_code">
<pre>>>> np.genfromtxt(<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">data.csv</span><span style="color: rgba(128, 0, 0, 1)">'</span>,delimiter=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">,</span><span style="color: rgba(128, 0, 0, 1)">'</span>,skip_header=1<span style="color: rgba(0, 0, 0, 1)">)
array([[ </span>1., 100., 101<span style="color: rgba(0, 0, 0, 1)">.],
[ </span>2., 200., 230<span style="color: rgba(0, 0, 0, 1)">.],
[ </span>3., 300., 350.]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">读取外部数据的方法不止np.genfromtxt(),还有np.load(等,但numpy读取外部数据的应用情况其实并不多,这里不再细说。</p>
<h1 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> 3 numpy中数组的数据类型</h1>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">作为一个强大的科学计算库,numpy中支持的数据类型远不止Python原生的几种数据类型。如下所示为numpy中支持的数据类型:</p>
<div style="overflow: auto">
<table class="chb_table_class" style="border-collapse: collapse; table-layout: fixed; white-space: nowrap; width: 0" align="center"><colgroup><col style="width: 70px"><col style="width: 542px"></colgroup>
<tbody>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-0-0">
<div class="table-cell-line" style="text-align: center"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">数据类型</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-0-1">
<div class="table-cell-line" style="text-align: center"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">描述</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-1-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">bool_</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-1-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">布尔(True或False),存储为一个字节</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-2-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">int_</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-2-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">默认整数类型(与C<span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">long<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">相同;通常是<span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">int64<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">或<span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">int32<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">)</span></span></span></span></span></span></span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-3-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">INTC</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-3-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">与C<span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">int<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">(通常为<span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">int32<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">或<span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">int64<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">)相同</span></span></span></span></span></span></span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-4-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">INTP</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-4-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">用于索引的整数(与C<span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">ssize_t<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">相同;通常是<span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">int32<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">或<span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">int64<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">)</span></span></span></span></span></span></span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-5-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">INT8</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-5-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">字节(-128至127)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-6-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">INT16</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-6-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">整数(-32768至32767)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-7-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">INT32</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-7-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">整数(-2147483648至2147483647)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-8-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">Int64的</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-8-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">整数(-9223372036854775808至9223372036854775807)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-9-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">UINT8</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-9-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">无符号整数(0到255)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-10-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">UINT16</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-10-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">无符号整数(0到65535)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-11-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">UINT32</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-11-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">无符号整数(0到4294967295)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-12-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">UINT64</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-12-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">无符号整数(0到18446744073709551615)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-13-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">float_</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-13-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">float64<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">的简写。</span></span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-14-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">float16</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-14-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">半精度浮点:符号位,5位指数,10位尾数</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-15-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">FLOAT32</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-15-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">单精度浮点数:符号位,8位指数,23位尾数</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-16-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">float64</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-16-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">双精度浮点:符号位,11位指数,52位尾数</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-17-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">complex_</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-17-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: monospace; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">complex128<span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">的简写。</span></span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-18-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">complex64</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-18-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">复数,由两个32位浮点数(实部和虚部)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-19-0">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">complex128</span></div>
</td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; word-wrap: break-word; white-space: pre-wrap" data-cell-id="1890-1566640202022-cell-19-1">
<div class="table-cell-line"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">复数,由两个64位浮点数(实部和虚部)</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">这些数据类型可以通过如np.bool_、np.float16等形式来调用,上文中提到过,创建数组时可以指定数据类型:</p>
<div class="cnblogs_code">
<pre>>>> a = np.array(, dtype=<span style="color: rgba(0, 0, 0, 1)">np.bool_)
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array()</span></pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">可以通过numpy数组自带的dtype属性来查看数组的数据类型:</p>
<div class="cnblogs_code">
<pre>>>><span style="color: rgba(0, 0, 0, 1)"> a.dtype
dtype(</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">bool</span><span style="color: rgba(128, 0, 0, 1)">'</span>)</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">为什么输出的类型是bool而不是bool_呢?因为numpy中后缀带下划线“_”的数据类型指向的就是Python原生的数据类型,也就是说,np.bool_与Python中的bool数据类型等效,np.float_与Python中的float类型等效。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">当一个数组已经被创建,但是想要改变其数据类型,那就可以通过np.asdtype()方法:</p>
<div class="cnblogs_code">
<pre>>>><span style="color: rgba(0, 0, 0, 1)"> a.astype(np.int)
array()
</span>>>> a = np.random.random((2,2<span style="color: rgba(0, 0, 0, 1)">))
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([[</span>0.02914317, 0.645534<span style="color: rgba(0, 0, 0, 1)"> ],
[</span>0.61839509, 0.64155607<span style="color: rgba(0, 0, 0, 1)">]])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a.dtype
dtype(</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">float64</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">)
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a.astype(np.float16)
array([[</span>0.02914, 0.6455<span style="color: rgba(0, 0, 0, 1)"> ],
[</span>0.618 , 0.6416 ]], dtype=<span style="color: rgba(0, 0, 0, 1)">float16)
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a.dtype
dtype(</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">float64</span><span style="color: rgba(128, 0, 0, 1)">'</span>)</pre>
</div>
<h1 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">4 numpy中数组的形状</h1>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">numpy中数组使用与存放多维数据,所以,所谓数组的形状指的就是数据的维度大小,以及每一维度元素个数。我们可以通过数组自带的shape属性来查看形状信息:</p>
<div class="cnblogs_code">
<pre>>>> a = np.array([, ])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([[</span>2, 3, 4<span style="color: rgba(0, 0, 0, 1)">],
[</span>5, 6, 7<span style="color: rgba(0, 0, 0, 1)">]])
</span>>>> a.shape <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 查看形状属性</span>
(2, 3)</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">可以看到,查看形状属性时返回的是一个元组,元素的长度代表数组的维度,元组每一个属性代表对应的维度的元素个数,(2,3)就表示第一个维度元素个数是2(两行),第二个维度长度是3(3列)。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">在数组创建之后,数组的形状也是可以改变的。改变数组的形状通过数组的reshape()方法:</p>
<div class="cnblogs_code">
<pre>>>> a = np.ones((2, 12<span style="color: rgba(0, 0, 0, 1)">))
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([[</span>1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.]])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a.shape
(</span>2, 12<span style="color: rgba(0, 0, 0, 1)">)
</span>>>> b = a.reshape(2, 3, 4<span style="color: rgba(0, 0, 0, 1)">)
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b
array([[[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.]],
[[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.]]])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b.shape
(</span>2, 3, 4<span style="color: rgba(0, 0, 0, 1)">)
</span>>>> b = a.reshape((2,3,4)) <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 元组作为参数</span>
>>><span style="color: rgba(0, 0, 0, 1)"> b
array([[[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.]],
[[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.],
[</span>1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.]]])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b.shape
(</span>2, 3, 4)</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">可以看到,np.reshape()方法可以同时传入多个描述形状的数字,也可以传入一个数组,当然,如果将形状改变为一维数组时,必须传入的是元组。另外需要注意,传入reshape方法的多个参数的乘积必须与改变前数组总长度相等,否则会报错。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">numpy数组中专门提供了一个方法加你个数组转换为以为数组,那就是flatten()方法,这个方法在执行数组运算是非常有用:</p>
<div class="cnblogs_code">
<pre>>>> a = np.ones((2, 3<span style="color: rgba(0, 0, 0, 1)">))
</span>>>> b =<span style="color: rgba(0, 0, 0, 1)"> a.flatten()
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b
array([</span>1., 1., 1., 1., 1., 1<span style="color: rgba(0, 0, 0, 1)">.])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b.shape
(</span>6,)</pre>
</div>
<h1 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">5 索引与切片</h1>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">对数据使用时,不可避免要进行索引和切片,numpy在这一方面不可谓不强大。numpy数组中所有的索引都是从0开始的,我们可以根据索引来精确取数据。</p>
<h2 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">5.1 按索引取值</h2>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">下面所有实例都已下方数组a来展开:</p>
<div class="cnblogs_code">
<pre>>>> a = np.arange(36).reshape((4, 9<span style="color: rgba(0, 0, 0, 1)">))
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([[ 0, </span>1, 2, 3, 4, 5, 6, 7, 8<span style="color: rgba(0, 0, 0, 1)">],
[ </span>9, 10, 11, 12, 13, 14, 15, 16, 17<span style="color: rgba(0, 0, 0, 1)">],
[</span>18, 19, 20, 21, 22, 23, 24, 25, 26<span style="color: rgba(0, 0, 0, 1)">],
[</span>27, 28, 29, 30, 31, 32, 33, 34, 35]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(1)取一行</strong></p>
<div class="cnblogs_code">
<pre>>>> a <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 取第二行数据</span>
array([ 9, 10, 11, 12, 13, 14, 15, 16, 17])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(2)取连续多行数据</strong></p>
<div class="cnblogs_code">
<pre>>>> a[:2] <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 取前两行数据</span>
array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8<span style="color: rgba(0, 0, 0, 1)">],
[ </span>9, 10, 11, 12, 13, 14, 15, 16, 17]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">也可以加上步长:</p>
<div class="cnblogs_code">
<pre>>>> a[::2] <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 每隔一行取一次</span>
array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8<span style="color: rgba(0, 0, 0, 1)">],
[</span>18, 19, 20, 21, 22, 23, 24, 25, 26<span style="color: rgba(0, 0, 0, 1)">]])
</span>>>> a <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 取第2行后面所有行</span>
array([[ 9, 10, 11, 12, 13, 14, 15, 16, 17<span style="color: rgba(0, 0, 0, 1)">],
[</span>18, 19, 20, 21, 22, 23, 24, 25, 26<span style="color: rgba(0, 0, 0, 1)">],
[</span>27, 28, 29, 30, 31, 32, 33, 34, 35]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(3)取不连续多行数据</strong></p>
<div class="cnblogs_code">
<pre>>>> a[] <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 取第一行和最后一行</span>
>>> a[]
array([[ 0, </span>1, 2, 3, 4, 5, 6, 7, 8<span style="color: rgba(0, 0, 0, 1)">],
[</span>27, 28, 29, 30, 31, 32, 33, 34, 35]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">可以看到,对numpy根据索引进行取值的方法与Python中list索引取值方法类似,都是通过方括号里面传入索引取值,当需要对多维进行索引时,每一位数据之间用逗号隔开。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(4)取一列</strong></p>
<div class="cnblogs_code">
<pre>>>> a[:,1] <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 取第2列</span>
array([ 1, 10, 19, 28])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(5)取连续多列</strong></p>
<div class="cnblogs_code">
<pre>>>> a[:,1:3] <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 取第2列到第3列</span>
array([[ 1, 2<span style="color: rgba(0, 0, 0, 1)">],
[</span>10, 11<span style="color: rgba(0, 0, 0, 1)">],
[</span>19, 20<span style="color: rgba(0, 0, 0, 1)">],
[</span>28, 29]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(6)取不连续多列</strong></p>
<div class="cnblogs_code">
<pre>>>> a[:,] <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 取第1列和第4列</span>
array([[ 0, 3<span style="color: rgba(0, 0, 0, 1)">],
[ </span>9, 12<span style="color: rgba(0, 0, 0, 1)">],
[</span>18, 21<span style="color: rgba(0, 0, 0, 1)">],
[</span>27, 30]]))</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(7)取连续多行多列</strong></p>
<div class="cnblogs_code">
<pre>>>> a <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 取第2、3行中的第2、3列</span>
array([,
[</span>19, 20]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(8)取多个不连续位置数据</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">看到这里你应该也明白了取行、取列的规律了,如果取不连续的多行多列呢?例如取第1、3行与第2、4列,你可能认为是a[, ],我们来看看:</p>
<div class="cnblogs_code">
<pre>>>> a[, ]
array([ </span>1, 21])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">可见,返回的并不是预期的数据,而是第1行第2列、第3行第4列的数据,也就是(0,1)和(2,3)位置的数据。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">从而我们可以得出结论,如果取第3行中第3列、第5列,第4行中第1列、第7列数据方法如下:</p>
<div class="cnblogs_code">
<pre>>>> a[,] <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 第3行中第3列、第5列,第4行中第1列、第7列数据</span>
array()</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(9)取单个数据</strong></p>
<div class="cnblogs_code">
<pre>>>> b = a
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b
</span>30
>>> type(b) <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 取单个类型是返回的就是一个确切的numpy类型数值</span>
<<span style="color: rgba(0, 0, 255, 1)">class</span> <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">numpy.int64</span><span style="color: rgba(128, 0, 0, 1)">'</span>></pre>
</div>
<h2 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">5.2 bool索引</h2>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(1)bool索引取值</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">numpy中提供了一些通用函数来实现通过bool条件判断实现按条件取值,使用这些通用方法,与使用对应的符号时等效的,符号与numpy通用方法对应关系如下:</p>
<div style="overflow: auto">
<table class="table table-striped" style="border-collapse: collapse; table-layout: fixed; white-space: nowrap; width: 0"><colgroup><col style="width: 70px"><col style="width: 533px"></colgroup>
<tbody>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-0-0"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">运算符</span></td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-0-1"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">对应的通用函数</span></td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-1-0"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">==</span></td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-1-1"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">np.equal</span></td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-2-0"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">!=</span></td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-2-1"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">np.not_equal</span></td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-3-0"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none"><</span></td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-3-1"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">np.less</span></td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-4-0"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none"><=</span></td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-4-1"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">np.less_equal</span></td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-5-0"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">></span></td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-5-1"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">np.greater</span></td>
</tr>
<tr style="height: 40px">
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-6-0"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">>=</span></td>
<td style="font-size: 14px; color: rgba(57, 57, 57, 1); border: 1px solid rgba(167, 167, 167, 1); overflow: hidden; vertical-align: middle; overflow-wrap: break-word; white-space: pre-wrap; text-align: center" data-cell-id="8782-1566713528597-cell-6-1"><span style="font-size: 14px; font-family: Microsoft YaHei, STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">np.greater_equal</span></td>
</tr>
</tbody>
</table>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">我们通过实例感受一下:</p>
<div class="cnblogs_code">
<pre>>>> a = np.arange(24).reshape((4,6<span style="color: rgba(0, 0, 0, 1)">))
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([[ 0, </span>1, 2, 3, 4, 5<span style="color: rgba(0, 0, 0, 1)">],
[ </span>6, 7, 8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">],
[</span>12, 13, 14, 15, 16, 17<span style="color: rgba(0, 0, 0, 1)">],
[</span>18, 19, 20, 21, 22, 23<span style="color: rgba(0, 0, 0, 1)">]])
</span>>>> b = a<5 <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> bool索引选取</span>
>>><span style="color: rgba(0, 0, 0, 1)"> b
array([[ True, True, True, True, True, False],
,
,
])</span></pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">可以看到,在元素值小于5的位置上值为True,不满足条件的为False。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">也可以使用通用函数实现:</p>
<div class="cnblogs_code">
<pre>>>> b = np.less(a,5) <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 通用函数选取</span>
>>><span style="color: rgba(0, 0, 0, 1)"> b
array([[ True, True, True, True, True, False],
,
,
])</span></pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">对bool索引选取出来的结果全是True或者False,可能不是你想要的,可以进一步使用:</p>
<div class="cnblogs_code">
<pre>>>><span style="color: rgba(0, 0, 0, 1)"> a
array()</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">所以我们可以直接刷选值:</p>
<div class="cnblogs_code">
<pre>>>> a
array()</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(2)三目元算</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">numpy中提供了一个where()方法来实现三目运算。where()方法接受三个参数,第一个参数是判断条件,第二个参数时时判断条件为真时数组中满足条件的元素将要替换的值,第三个参数是判断调价为假时不满足条件元素将要替换的值。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">例如,将数组中所有满足元素值小于5的数值替换为0,不满足的元素值替换为1:</p>
<div class="cnblogs_code">
<pre>>>> a = np.arange(24).reshape((4,6<span style="color: rgba(0, 0, 0, 1)">))
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([[ 0, </span>1, 2, 3, 4, 5<span style="color: rgba(0, 0, 0, 1)">],
[ </span>6, 7, 8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">],
[</span>12, 13, 14, 15, 16, 17<span style="color: rgba(0, 0, 0, 1)">],
[</span>18, 19, 20, 21, 22, 23<span style="color: rgba(0, 0, 0, 1)">]])
</span>>>> np.where(a<5, 0, 1) <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 三目运算</span>
array([,
[</span>1, 1, 1, 1, 1, 1<span style="color: rgba(0, 0, 0, 1)">],
[</span>1, 1, 1, 1, 1, 1<span style="color: rgba(0, 0, 0, 1)">],
[</span>1, 1, 1, 1, 1, 1]])</pre>
</div>
<h1 style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">6 numpy中赋值、视图、深复制</h1>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(1)赋值</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">当对numpy数组进行赋值时,只是对同一个对象新建了一个引用,并不是建立新的对象,所以赋值前后的变量完全是同一对象,对其中一个引用修改时,所有引用都会生效:</p>
<div class="cnblogs_code">
<pre>>>> a = np.arange(12<span style="color: rgba(0, 0, 0, 1)">)
</span>>>> b = a <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 赋值</span>
>>> a <span style="color: rgba(0, 0, 255, 1)">is</span><span style="color: rgba(0, 0, 0, 1)"> b
True
</span>>>> b.shape = (3, 4<span style="color: rgba(0, 0, 0, 1)">)
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b
array([[ 0, </span>1, 2, 3<span style="color: rgba(0, 0, 0, 1)">],
[ </span>4, 5, 6, 7<span style="color: rgba(0, 0, 0, 1)">],
[ </span>8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">]])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([[ 0, </span>1, 2, 3<span style="color: rgba(0, 0, 0, 1)">],
[ </span>4, 5, 6, 7<span style="color: rgba(0, 0, 0, 1)">],
[ </span>8, 9, 10, 11]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(2)视图(切片、浅复制)</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">numpy中允许不同数组间共享数据,这种机制在numpy中称为视图,对numpy数组的切片和浅复制都是通过视图实现的。如果数组B是数组A的视图(view),则称A为B的base(除非A也是视图)。视图数组中的数据实际上保存在base数组中。</p>
<div class="cnblogs_code">
<pre>>>> a = np.arange(12<span style="color: rgba(0, 0, 0, 1)">)
</span>>>> b = a.view() <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 使用视图</span>
>>> a <span style="color: rgba(0, 0, 255, 1)">is</span><span style="color: rgba(0, 0, 0, 1)"> b
False
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b
array([ 0, </span>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">])
</span>>>> b.shape = (3, 4) <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 改变b的形状</span>
>>><span style="color: rgba(0, 0, 0, 1)"> a
array([ 0, </span>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b
array([[ 0, </span>1, 2, 3<span style="color: rgba(0, 0, 0, 1)">],
[ </span>4, 5, 6, 7<span style="color: rgba(0, 0, 0, 1)">],
[ </span>8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">]])
</span>>>> b =<span style="color: rgba(0, 0, 0, 1)"> 0
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([ 0, 0, 0, 0, </span>4, 5, 6, 7, 8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b
array([[ 0, 0, 0, 0],
[ </span>4, 5, 6, 7<span style="color: rgba(0, 0, 0, 1)">],
[ </span>8, 9, 10, 11]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">从上面代码中我们可以发现,a和b是不同的两个数组,改变b的形状对a不会有影响,但是改变b的数据之后,a的数据也会发现改变,说明a与b是共享数据的。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> 再来探索一些切片:</p>
<div class="cnblogs_code">
<pre>>>> a = np.arange(12<span style="color: rgba(0, 0, 0, 1)">)
</span>>>> b = a[:] <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 切片</span>
>>> a <span style="color: rgba(0, 0, 255, 1)">is</span><span style="color: rgba(0, 0, 0, 1)"> b
False
</span>>>> b.shape = (3, 4<span style="color: rgba(0, 0, 0, 1)">)
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([ 0, </span>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b
array([[ 0, </span>1, 2, 3<span style="color: rgba(0, 0, 0, 1)">],
[ </span>4, 5, 6, 7<span style="color: rgba(0, 0, 0, 1)">],
[ </span>8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">]])
</span>>>> b =<span style="color: rgba(0, 0, 0, 1)"> 0
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([ 0, 0, 0, 0, </span>4, 5, 6, 7, 8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b
array([[ 0, 0, 0, 0],
[ </span>4, 5, 6, 7<span style="color: rgba(0, 0, 0, 1)">],
[ </span>8, 9, 10, 11]])</pre>
</div>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">果然,切片效果与视图一致。</p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><strong>(3)深复制</strong></p>
<p style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">深复制通过数组自带的copy()方法实现,深复制产生的数组与原数组时完全不同的两个数组对象,完全享有独立的内存空间,所有操作都不会相互影响。</p>
<div class="cnblogs_code">
<pre>>>> a = np.arange(12<span style="color: rgba(0, 0, 0, 1)">)
</span>>>> b =<span style="color: rgba(0, 0, 0, 1)"> a.copy()
</span>>>> a <span style="color: rgba(0, 0, 255, 1)">is</span><span style="color: rgba(0, 0, 0, 1)"> b
False
</span>>>> b.shape = (3, 4<span style="color: rgba(0, 0, 0, 1)">)
</span>>>> b =<span style="color: rgba(0, 0, 0, 1)"> 0
</span>>>><span style="color: rgba(0, 0, 0, 1)"> a
array([ 0, </span>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11<span style="color: rgba(0, 0, 0, 1)">])
</span>>>><span style="color: rgba(0, 0, 0, 1)"> b
array([[ 0, 0, 0, 0],
[ </span>4, 5, 6, 7<span style="color: rgba(0, 0, 0, 1)">],
[ </span>8, 9, 10, 11]])</pre>
</div>
<p> </p>
</div>
<div id="MySignature" role="contentinfo">
<hr style="display: block; margin-top: 23px; color: #eee">
<div style="height: 280px;margin-top:15px; width: 100%; background: #eee">
<div style="float: left; margin-top: 25px; margin-left: 25px; height: 235px; width: 21%; background: black">
<img style="width: 100%; height: 100%" src="https://files.cnblogs.com/files/chenhuabin/wechat.gif">
</div>
<div style="float: left; margin-top: 25px; margin-left: 25px; height: 200px; width: 70%; border-left: 1px">
<p style="padding: 2px 17px 0px 15px; text-indent: 0;font-size: 18px"><b> 作者</b>:奥辰</p>
<p style="padding: 0px 17px 0px 15px; text-indent: 0;font-size: 18px"><b>微信号</b>:chb1137796095</p>
<p style="padding: 0px 17px 0px 15px; text-indent: 0;font-size: 18px">
<b>Github</b>:https://github.com/ChenHuabin321</p>
<p style="padding: 0px 17px 0px 15px;text-indent: 0; font-size: 18px">欢迎加V交流,共同学习,共同进步!</p>
<p style="padding-left: 13px; text-indent: 0;font-size: 18px">本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。</p>
</div>
</div><br><br>
来源:https://www.cnblogs.com/chenhuabin/p/11412818.html
頁:
[1]