NumPy简明教程(二、数组1)

http://blog.csdn.net/sunny2038/article/details/9002531

NumPy数组(1、数组初探)

更新

目前我的工作是将NumPy引入到Pyston中(一款Dropbox实现的Python编译器/解释器)。在工作过程中,我深入接触了NumPy源码,了解其实现并提交了PR修复NumPy的bug。在与NumPy源码以及NumPy开发者打交道的过程中,我发现当今中文NumPy教程大部分都是翻译或参考英文文档,因此导致了许多疏漏。比如NumPy数组中的broadcast功能,几乎所有中文文档都翻译为“广播”。而NumPy的开发者之一,回复到“broadcast is a compound -- native English speakers can see that it's " broad" + "cast" = "cast (scatter, distribute) broadly, I guess "cast (scatter, distribute) broadly" probably is closer to the meaning(NumPy中的含义)"。有鉴于此,我打算启动一个项目,以我对NumPy使用以及源码层面的了解编写一个系列的教程。

地址随后会更新。CSDN的排版(列表)怎么显示不正常了。。。

NumPy数组

NumPy数组是一个多维数组对象,称为ndarray。其由两部分组成:

  • 实际的数据
  • 描述这些数据的元数据

大部分操作仅针对于元数据,而不改变底层实际的数据。

关于NumPy数组有几点必需了解的:

  • NumPy数组的下标从0开始。
  • 同一个NumPy数组中所有元素的类型必须是相同的。

NumPy数组属性

在详细介绍NumPy数组之前。先详细介绍下NumPy数组的基本属性。NumPy数组的维数称为秩(rank),一维数组的秩为1,二维数组的秩为2,以此类推。在NumPy中,每一个线性的数组称为是一个轴(axes),秩其实是描述轴的数量。比如说,二维数组相当于是两个一维数组,其中第一个一维数组中每个元素又是一个一维数组。所以一维数组就是NumPy中的轴(axes),第一个轴相当于是底层数组,第二个轴是底层数组里的数组。而轴的数量——秩,就是数组的维数。

NumPy的数组中比较重要ndarray对象属性有:

  • ndarray.ndim:数组的维数(即数组轴的个数),等于秩。最常见的为二维数组(矩阵)。
  • ndarray.shape:数组的维度。为一个表示数组在每个维度上大小的整数元组。例如二维数组中,表示数组的“行数”和“列数”。ndarray.shape返回一个元组,这个元组的长度就是维度的数目,即ndim属性。
  • ndarray.size:数组元素的总个数,等于shape属性中元组元素的乘积。
  • ndarray.dtype:表示数组中元素类型的对象,可使用标准的Python类型创建或指定dtype。另外也可使用前一篇文章中介绍的NumPy提供的数据类型。
  • ndarray.itemsize:数组中每个元素的字节大小。例如,一个元素类型为float64的数组itemsiz属性值为8(float64占用64个bits,每个字节长度为8,所以64/8,占用8个字节),又如,一个元素类型为complex32的数组item属性为4(32/8)。
  • ndarray.data:包含实际数组元素的缓冲区,由于一般通过数组的索引获取元素,所以通常不需要使用这个属性。

创建数组

<span style="font-size: 18px;">  <span style="font-family: SimSun; font-size: 14px;"><span lang="zh-CN">先来介绍</span>创建数组。<span lang="zh-CN">创建数组的方法有很多。</span>如可以使用<span lang="en-US">array</span>函数从常规的<span lang="en-US">Python</span>列表和元组创造数组。所创建的数组类型由原序列中的元素类型推导而来。</span><span style="font-family: SimSun;">   </span></span><div class="dp-highlighter bg_python" style="font-family: Consolas, "Courier New", Courier, mono, serif; font-size: 12px; width: 700.92px; overflow-x: auto; overflow-y: hidden; padding-top: 1px; position: relative; margin: 18px 0px !important; background-color: rgb(231, 229, 220);"><div class="bar" style="padding-left: 45px;"><div class="tools eye-protector-processed" style="padding: 3px 8px 10px 10px; font-stretch: normal; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); border-left: 3px solid rgba(0, 0, 0, 0.34902); transition: background 0.3s ease; border-top-color: rgba(0, 0, 0, 0.34902); border-bottom-color: rgba(0, 0, 0, 0.34902); border-right-color: rgba(0, 0, 0, 0.34902); background-color: rgb(193, 230, 198);"><strong>[python]</strong> <a target=_blank href="http://blog.csdn.net/sunny2038/article/details/9002531#" class="ViewSource eye-protector-processed" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; border: none rgba(0, 0, 0, 0.34902); padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; transition: background 0.3s ease; background-image: url("images/default/ico_plain.gif"); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: left top; background-repeat: no-repeat;">view plain</a><span data-mod="popu_168"> <a target=_blank href="http://blog.csdn.net/sunny2038/article/details/9002531#" class="CopyToClipboard eye-protector-processed" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; border: none rgba(0, 0, 0, 0.34902); padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-image: url("images/default/ico_copy.gif"); background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: left top; background-repeat: no-repeat;">copy</a></span><div style="position: absolute; left: 433px; top: 1850px; width: 18px; height: 18px; z-index: 99;"></div><span data-mod="popu_169"> </span></div></div><ol start="1" class="dp-py eye-protector-processed" style="padding: 0px; border: none; color: rgb(92, 92, 92); transition: background 0.3s ease; margin: 0px 0px 1px 45px !important; background-color: rgb(193, 230, 198);"><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">>>> </span><span class="keyword eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 102, 153); font-weight: bold; transition: background 0.3s ease;">from</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> numpy </span><span class="keyword eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 102, 153); font-weight: bold; transition: background 0.3s ease;">import</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> *  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">     </span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> a = array( [<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">2</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">,</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">3</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">,</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">4</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">] )     </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> a  </span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    array([<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">2</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">, </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">3</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">, </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">4</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">])  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> a.dtype  </span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    dtype(<span class="string eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: blue; transition: background 0.3s ease;">'int32'</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">)  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> b = array([<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">1.2</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">, </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">3.5</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">, </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">5.1</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">])     </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> b.dtype  </span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    dtype(<span class="string eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: blue; transition: background 0.3s ease;">'float64'</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">)  </span></span></li></ol></div>

使用array函数创建时,参数必须是由方括号括起来的列表,而不能使用多个数值作为参数调用array。

[python] view plain copy

  1. >>> a = array(1,2,3,4)    # 错误
  2. >>> a = array([1,2,3,4])  # 正确

可使用双重序列来表示二维的数组,三重序列表示三维数组,以此类推。

[python] view plain copy

  1. >>> b = array( [ (1.5,2,3), (4,5,6) ] )    
  2. >>> b  
  3.     array([[ 1.5,  2. ,  3. ],  
  4.         [ 4. ,  5. ,  6. ]])  

可以在创建时显式指定数组中元素的类型

[python] view plain copy

  1. >>> c = array( [ [1,2], [3,4] ], dtype=complex)  
  2. >>> c  
  3.     array([[ 1.+0.j,  2.+0.j],  
  4.        [ 3.+0.j,  4.+0.j]])  

通常,刚开始时数组的元素未知,而数组的大小已知。因此,NumPy提供了一些使用占位符创建数组的函数。这些函数有助于满足除了数组扩展的需要,同时降低了高昂的运算开销。

用函数zeros可创建一个全是0的数组,用函数ones可创建一个全为1的数组,函数empty创建一个内容随机并且依赖与内存状态的数组。默认创建的数组类型(dtype)都是float64。

可以哟娜特d.dtype.itemsize来查看数组中元素占用的字节数目。

[python] view plain copy

  1. >>> d = zeros((3,4))  
  2. >>> d.dtype  
  3. dtype('float64')  
  4. >>> d  
  5. array([[ 0.,  0.,  0.,  0.],  
  6.      [ 0.,  0.,  0.,  0.],  
  7.      [ 0.,  0.,  0.,  0.]])  
  8. >>> d.dtype.itemsize  
  9. 8

也可以自己制定数组中元素的类型

[python] view plain copy

  1. >>> ones( (2,3,4), dtype=int16 )  #手动指定数组中元素类型
  2.       array([[[1, 1, 1, 1],  
  3.            [1, 1, 1, 1],  
  4.            [1, 1, 1, 1]],  
  5.           [[1, 1, 1, 1],  
  6.            [1, 1, 1, 1],  
  7.            [1, 1, 1, 1]]], dtype=int16)  
  8. >>> empty((2,3))  
  9.    array([[  2.65565858e-316,   0.00000000e+000,   0.00000000e+000],  
  10.           [  0.00000000e+000,   0.00000000e+000,   0.00000000e+000]])  

NumPy提供一个类似arange的函数返回一个数列形式的数组:

[python] view plain copy

  1. >>> arange(10, 30, 5)  
  2.     array([10, 15, 20, 25])  

以10开始,差值为5的等差数列。该函数不仅接受整数,还接受浮点参数: 

[python] view plain copy

  1. >>> arange(0,2,0.5)  
  2.     array([ 0. ,  0.5,  1. ,  1.5])  

当arange使用浮点数参数时,由于浮点数精度有限,通常无法预测获得的元素个数。因此,最好使用函数linspace去接收我们想要的元素个数来代替用range来指定步长。linespace用法如下,将在通用函数一节中详细介绍。

[python] view plain copy

  1. >>> numpy.linspace(-1, 0, 5)  
  2.         array([-1.  , -0.75, -0.5 , -0.25,  0.  ])  

数组中的元素是通过下标来访问的,可以通过方括号括起一个下标来访问数组中单一一个元素,也可以以切片的形式访问数组中多个元素。关于切片访问,将在切片一节介绍。

知识点:NumPy中的数据类型 对于科学计算来说,Python中自带的整型、浮点型和复数类型远远不够,因此NumPy中添加了许多数据类型。如下:

名称

描述

bool

用一个字节存储的布尔类型(True或False)

inti

由所在平台决定其大小的整数(一般为int32或int64)

int8

一个字节大小,-128 至 127

int16

整数,-32768 至 32767

int32

整数,-2 ** 31 至 2 ** 32 -1

int64

整数,-2 ** 63 至 2 ** 63 - 1

uint8

无符号整数,0 至 255

uint16

无符号整数,0 至 65535

uint32

无符号整数,0 至 2 ** 32 - 1

uint64

无符号整数,0 至 2 ** 64 - 1

float16

半精度浮点数:16位,正负号1位,指数5位,精度10位

float32

单精度浮点数:32位,正负号1位,指数8位,精度23位

float64或float

双精度浮点数:64位,正负号1位,指数11位,精度52位

complex64

复数,分别用两个32位浮点数表示实部和虚部

complex128或complex

复数,分别用两个64位浮点数表示实部和虚部

NumPy类型转换方式如下:

[python] view plain copy

  1. >>> float64(42)  
  2. 42.0
  3. >>> int8(42.0)  
  4. 42
  5. >>> bool(42)  
  6. True
  7. >>> bool(42.0)  
  8. True
  9. >>> float(True)  
  10. 1.0

许多函数的参数中可以指定参数的类型,当然,这个类型参数是可选的。如下:

[python] view plain copy

  1. >>> arange(7, dtype=uint16)  
  2.     array([0, 1, 2, 3, 4, 5, 6], dtype=uint16)  

输出数组

<span style="font-size: 18px;">    <span style="font-size: 14px;">当输出一个数组时,<span style="font-family: "Courier New", monospace;"><span lang="en-US">NumPy</span></span>以特定的布局用类似嵌套列表的形式显示:
</span></span>
  • 第一行从左到右输出
  • 每行依次自上而下输出
  • 每个切片通过一个空行与下一个隔开
  • 一维数组被打印成行,二维数组成矩阵,三维数组成矩阵列表。
<span style="font-size: 18px;">    
</span><div class="dp-highlighter bg_python" style="font-family: Consolas, "Courier New", Courier, mono, serif; font-size: 12px; width: 700.92px; overflow-x: auto; overflow-y: hidden; padding-top: 1px; position: relative; margin: 18px 0px !important; background-color: rgb(231, 229, 220);"><div class="bar" style="padding-left: 45px;"><div class="tools eye-protector-processed" style="padding: 3px 8px 10px 10px; font-stretch: normal; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); border-left: 3px solid rgba(0, 0, 0, 0.34902); transition: background 0.3s ease; border-top-color: rgba(0, 0, 0, 0.34902); border-bottom-color: rgba(0, 0, 0, 0.34902); border-right-color: rgba(0, 0, 0, 0.34902); background-color: rgb(193, 230, 198);"><strong>[python]</strong> <a target=_blank href="http://blog.csdn.net/sunny2038/article/details/9002531#" class="ViewSource eye-protector-processed" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; border: none rgba(0, 0, 0, 0.34902); padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; transition: background 0.3s ease; background-image: url("images/default/ico_plain.gif"); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: left top; background-repeat: no-repeat;">view plain</a><span data-mod="popu_168"> <a target=_blank href="http://blog.csdn.net/sunny2038/article/details/9002531#" class="CopyToClipboard eye-protector-processed" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; border: none rgba(0, 0, 0, 0.34902); padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-image: url("images/default/ico_copy.gif"); background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: left top; background-repeat: no-repeat;">copy</a></span><div style="position: absolute; left: 433px; top: 5111px; width: 18px; height: 18px; z-index: 99;"></div><span data-mod="popu_169"> </span></div></div><ol start="1" class="dp-py eye-protector-processed" style="padding: 0px; border: none; color: rgb(92, 92, 92); transition: background 0.3s ease; margin: 0px 0px 1px 45px !important; background-color: rgb(193, 230, 198);"><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">>>> a = arange(</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">6</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">)                         </span><span class="comment eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); transition: background 0.3s ease;"># 1d array</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> <span class="keyword eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 102, 153); font-weight: bold; transition: background 0.3s ease;">print</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> a  </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">0</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">1</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">2</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">3</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">4</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">5</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">     </span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> b = arange(<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">12</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">).reshape(</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">4</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">,</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">3</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">)           </span><span class="comment eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); transition: background 0.3s ease;"># 2d array</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> <span class="keyword eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 102, 153); font-weight: bold; transition: background 0.3s ease;">print</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> b  </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [[ <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">0</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">1</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">2</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [ <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">3</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">4</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">5</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [ <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">6</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">7</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">8</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [ <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">10</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">11</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]]     </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> c = arange(<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">24</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">).reshape(</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">2</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">,</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">3</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">,</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">4</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">)         </span><span class="comment eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); transition: background 0.3s ease;"># 3d array</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> <span class="keyword eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 102, 153); font-weight: bold; transition: background 0.3s ease;">print</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> c  </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [[[ <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">0</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">1</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">2</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">3</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [ <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">4</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">5</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">6</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">7</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [ <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">8</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">10</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">11</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]]  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">     </span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [[<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">12</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">13</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">14</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">15</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">16</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">17</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">18</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">19</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">20</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">21</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">22</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">23</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]]]  </span></span></li></ol></div><span style="font-size: 18px;"><span style="font-size: 14px;"><span style="font-family: SimSun;">    <span lang="en-US">reshape</span>将在下一篇文章中介绍 
    如果一个数组太长,则<span lang="en-US">NumPy</span>自动省略中间部分而只打印两端的数据:  </span> </span></span><div class="dp-highlighter bg_python" style="font-family: Consolas, "Courier New", Courier, mono, serif; font-size: 12px; width: 700.92px; overflow-x: auto; overflow-y: hidden; padding-top: 1px; position: relative; margin: 18px 0px !important; background-color: rgb(231, 229, 220);"><div class="bar" style="padding-left: 45px;"><div class="tools eye-protector-processed" style="padding: 3px 8px 10px 10px; font-stretch: normal; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); border-left: 3px solid rgba(0, 0, 0, 0.34902); transition: background 0.3s ease; border-top-color: rgba(0, 0, 0, 0.34902); border-bottom-color: rgba(0, 0, 0, 0.34902); border-right-color: rgba(0, 0, 0, 0.34902); background-color: rgb(193, 230, 198);"><strong>[python]</strong> <a target=_blank href="http://blog.csdn.net/sunny2038/article/details/9002531#" class="ViewSource eye-protector-processed" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; border: none rgba(0, 0, 0, 0.34902); padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; transition: background 0.3s ease; background-image: url("images/default/ico_plain.gif"); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: left top; background-repeat: no-repeat;">view plain</a><span data-mod="popu_168"> <a target=_blank href="http://blog.csdn.net/sunny2038/article/details/9002531#" class="CopyToClipboard eye-protector-processed" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; border: none rgba(0, 0, 0, 0.34902); padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-image: url("images/default/ico_copy.gif"); background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: left top; background-repeat: no-repeat;">copy</a></span><div style="position: absolute; left: 433px; top: 5569px; width: 18px; height: 18px; z-index: 99;"></div><span data-mod="popu_169"> </span></div></div><ol start="1" class="dp-py eye-protector-processed" style="padding: 0px; border: none; color: rgb(92, 92, 92); transition: background 0.3s ease; margin: 0px 0px 1px 45px !important; background-color: rgb(193, 230, 198);"><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">>>> </span><span class="keyword eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 102, 153); font-weight: bold; transition: background 0.3s ease;">print</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> arange(</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">10000</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">)  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">   [   <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">0</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">    </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">1</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">    </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">2</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> ..., </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9997</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9998</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9999</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">     </span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">>>> <span class="keyword eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 102, 153); font-weight: bold; transition: background 0.3s ease;">print</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> arange(</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">10000</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">).reshape(</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">100</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">,</span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">100</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">)  </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">   [[   <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">0</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">    </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">1</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">    </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">2</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> ...,   </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">97</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">   </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">98</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">   </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">99</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [ <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">100</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">101</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">102</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> ...,  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">197</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">198</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">199</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [ <span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">200</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">201</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">202</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> ...,  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">297</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">298</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">  </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">299</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    ...,  </span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9700</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9701</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9702</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> ..., </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9797</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9798</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9799</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9800</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9801</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9802</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> ..., </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9897</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9898</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9899</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]  </span></span></li><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;">    [<span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9900</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9901</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9902</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> ..., </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9997</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9998</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;"> </span><span class="number eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">9999</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">]]  </span></span></li></ol></div><span style="font-size: 18px;">
<span style="font-size: 14px;">  可通过</span></span><span style="font-size: 18px;"><span style="font-size: 14px;">设置<span style="font-family: "Courier New", monospace;"><span lang="en-US">printoptions</span></span>参数来</span></span><span style="font-size: 18px;"><span style="font-size: 14px;">禁用<span style="font-family: "Courier New", monospace;"><span lang="en-US">NumPy</span></span>的这种行为并强制打印整个数组。</span>
</span><pre class="cjk" name="code" style="white-space: pre-wrap; word-wrap: break-word;"><div class="dp-highlighter bg_python" style="font-family: Consolas, "Courier New", Courier, mono, serif; font-size: 12px; width: 700.92px; overflow-x: auto; overflow-y: hidden; padding-top: 1px; position: relative; margin: 18px 0px !important; background-color: rgb(231, 229, 220);"><div class="bar" style="padding-left: 45px;"><div class="tools eye-protector-processed" style="padding: 3px 8px 10px 10px; font-stretch: normal; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); border-left: 3px solid rgba(0, 0, 0, 0.34902); transition: background 0.3s ease; border-top-color: rgba(0, 0, 0, 0.34902); border-bottom-color: rgba(0, 0, 0, 0.34902); border-right-color: rgba(0, 0, 0, 0.34902); background-color: rgb(193, 230, 198);"><strong>[python]</strong> <a target=_blank href="http://blog.csdn.net/sunny2038/article/details/9002531#" class="ViewSource eye-protector-processed" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; border: none rgba(0, 0, 0, 0.34902); padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; transition: background 0.3s ease; background-image: url("images/default/ico_plain.gif"); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: left top; background-repeat: no-repeat;">view plain</a><span data-mod="popu_168"> <a target=_blank href="http://blog.csdn.net/sunny2038/article/details/9002531#" class="CopyToClipboard eye-protector-processed" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; border: none rgba(0, 0, 0, 0.34902); padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-image: url("images/default/ico_copy.gif"); background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: left top; background-repeat: no-repeat;">copy</a></span><div style="position: absolute; left: 433px; top: 5885px; width: 18px; height: 18px; z-index: 99;"></div><span data-mod="popu_169"> </span></div></div><ol start="1" class="dp-py eye-protector-processed" style="padding: 0px; border: none; color: rgb(92, 92, 92); transition: background 0.3s ease; margin: 0px 0px 1px 45px !important; background-color: rgb(193, 230, 198);"><li class="alt eye-protector-processed" style="border-top: none; border-right: none; border-bottom: none; border-left: 3px solid rgba(0, 0, 0, 0.34902); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; transition: background 0.3s ease; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: black; transition: background 0.3s ease;"><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">set_printoptions(threshold=</span><span class="string eye-protector-processed" style="margin: 0px; padding: 0px; border: none; color: blue; transition: background 0.3s ease;">'nan'</span><span class="eye-protector-processed" style="margin: 0px; padding: 0px; border: none; transition: background 0.3s ease;">)  </span></span></li></ol></div><span style="font-size: 18px;"><span id="_xhe_cursor"></span><span style="font-family: "Courier New", monospace;"><span lang="en-US"></span></span></span>

这样,输出时数组的所有元素都会显示出来。

未完待续,如有错误,敬请指正!

参考文献:

《NumPy for Beginner》 《Python科学计算》 《Tentative NumPy Tutorial》

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏codingforever

经典算法巡礼(四) -- 排序之希尔排序

希尔排序与之前的排序算法不同,她是以她的发明者Donald Shell来命名的。她是插入排序的一种改进版本。

7120
来自专栏Python小屋

Python中lambda表达式的常见用法

非常抱歉,昨天发的代码中有一处小错误,已通过留言的方式进行了纠正,详情请见【详解Python列表推导式】 lambda表达式常用来声明匿名函数,即没有函数名字的...

37390
来自专栏程序生活

最大连续子序列和

https://blog.csdn.net/bitcarmanlee/article/details/51526010

11620
来自专栏vue学习

JS数据结构与算法-队列

11210
来自专栏数据结构与算法

1341 与3和5无关的数

1341 与3和5无关的数 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 白银 Silver 题目描述 Description ...

28940
来自专栏debugeeker的专栏

《coredump问题原理探究》Linux x86版5.8节C风格数据结构内存布局之结构体数组结构体coredump

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xuzhina/article/detai...

9310
来自专栏数据结构与算法

P1062 数列

题目描述 给定一个正整数k(3≤k≤15),把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列,例如,当k=3时,这个序列是: 1,3,4,9,...

31070
来自专栏深度学习之tensorflow实战篇

python高阶函数:map(f,[list]),reduce(f,[list],可选初始值),

map,reduce和filter三个函数在python3和python2中发生了较大的差异。具体请看文章后面部分。 1. python的map()函数 ...

34840
来自专栏数据结构与算法

P3373 【模板】线段树 2 区间求和 区间乘 区间加

题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数加上x 2.将某区间每一个数乘上x 3.求出某区间每一个数的和 输入输出格式 输...

411110
来自专栏Vamei实验室

Python补充05 字符串格式化 (%操作符)

在许多编程语言中都包含有格式化字符串的功能,比如C和Fortran语言中的格式化输入输出。Python中内置有对字符串进行格式化的操作%。 模板 格式化字符串时...

24290

扫码关注云+社区

领取腾讯云代金券