# 创建数组的方式

>>> import numpy as np
>>> a = np.array([1,2,3])
>>> a
array([1, 2, 3])
>>> a.dtype
dtype('int64')

>>> b = np.array([1.1, 1.2, 1.3])
>>> b
array([1.1, 1.2, 1.3])
>>> b.dtype
dtype('float64')


## 多维数组

>>> m = np.array([(1,2,3), (4,5,6)])
>>> m
array([[1, 2, 3],
[4, 5, 6]])
>>> m.dtype
dtype('int64')


## 新建时指定数据类型

>>> m = np.array([(1,2,3), (4,5,6)], dtype=complex)
>>> m
array([[1.+0.j, 2.+0.j, 3.+0.j],
[4.+0.j, 5.+0.j, 6.+0.j]])
>>> m.dtype
dtype('complex128')


## 快速指定初始默认值

>>> np.zeros( (3,4) )
array([[0., 0., 0., 0.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]])
>>> np.ones( (2,3,4), dtype=np.int16 )
array([[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]],

[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]]], dtype=int16)
>>> np.empty( (2,3) )
array([[1., 2., 3.],
[4., 5., 6.]])


## 创建数字序列

>>> np.arange( 10, 30, 5 )
array([10, 15, 20, 25])
>>> np.arange( 1, 30, 5 )
array([ 1,  6, 11, 16, 21, 26])
>>> np.arange( 0.1, 1, 0.2 )
array([0.1, 0.3, 0.5, 0.7, 0.9])


## 浮点数精确度问题

>>> np.linspace( 0, 2, 9 )
array([0.  , 0.25, 0.5 , 0.75, 1.  , 1.25, 1.5 , 1.75, 2.  ])

>>> from numpy import pi
>>> x = np.linspace( 0, 2*pi, 100 )
>>> f = np.sin(x)
>>> f
array([ 0.00000000e+00,  6.34239197e-02,  1.26592454e-01,  1.89251244e-01,
2.51147987e-01,  3.12033446e-01,  3.71662456e-01,  4.29794912e-01,
4.86196736e-01,  5.40640817e-01,  5.92907929e-01,  6.42787610e-01,
6.90079011e-01,  7.34591709e-01,  7.76146464e-01,  8.14575952e-01,
8.49725430e-01,  8.81453363e-01,  9.09631995e-01,  9.34147860e-01,
9.54902241e-01,  9.71811568e-01,  9.84807753e-01,  9.93838464e-01,
9.98867339e-01,  9.99874128e-01,  9.96854776e-01,  9.89821442e-01,
9.78802446e-01,  9.63842159e-01,  9.45000819e-01,  9.22354294e-01,
8.95993774e-01,  8.66025404e-01,  8.32569855e-01,  7.95761841e-01,
7.55749574e-01,  7.12694171e-01,  6.66769001e-01,  6.18158986e-01,
5.67059864e-01,  5.13677392e-01,  4.58226522e-01,  4.00930535e-01,
3.42020143e-01,  2.81732557e-01,  2.20310533e-01,  1.58001396e-01,
9.50560433e-02,  3.17279335e-02, -3.17279335e-02, -9.50560433e-02,
-1.58001396e-01, -2.20310533e-01, -2.81732557e-01, -3.42020143e-01,
-4.00930535e-01, -4.58226522e-01, -5.13677392e-01, -5.67059864e-01,
-6.18158986e-01, -6.66769001e-01, -7.12694171e-01, -7.55749574e-01,
-7.95761841e-01, -8.32569855e-01, -8.66025404e-01, -8.95993774e-01,
-9.22354294e-01, -9.45000819e-01, -9.63842159e-01, -9.78802446e-01,
-9.89821442e-01, -9.96854776e-01, -9.99874128e-01, -9.98867339e-01,
-9.93838464e-01, -9.84807753e-01, -9.71811568e-01, -9.54902241e-01,
-9.34147860e-01, -9.09631995e-01, -8.81453363e-01, -8.49725430e-01,
-8.14575952e-01, -7.76146464e-01, -7.34591709e-01, -6.90079011e-01,
-6.42787610e-01, -5.92907929e-01, -5.40640817e-01, -4.86196736e-01,
-4.29794912e-01, -3.71662456e-01, -3.12033446e-01, -2.51147987e-01,
-1.89251244e-01, -1.26592454e-01, -6.34239197e-02, -2.44929360e-16])


# 打印数组

## print()

>>> a = np.arange(6)
>>> a
array([0, 1, 2, 3, 4, 5])
>>> print(a)
[0 1 2 3 4 5]

• 多维数组
>>> m = np.arange(12).reshape(2,6)
>>> m
array([[ 0,  1,  2,  3,  4,  5],
[ 6,  7,  8,  9, 10, 11]])
>>> print(m)
[[ 0  1  2  3  4  5]
[ 6  7  8  9 10 11]]


## 太大的数组打印

>>> print(np.arange(10000))
[   0    1    2 ... 9997 9998 9999]
>>> print(np.arange(10000).reshape(100,100))
[[   0    1    2 ...   97   98   99]
[ 100  101  102 ...  197  198  199]
[ 200  201  202 ...  297  298  299]
...
[9700 9701 9702 ... 9797 9798 9799]
[9800 9801 9802 ... 9897 9898 9899]
[9900 9901 9902 ... 9997 9998 9999]]


### 强制打印所有

>>> np.set_printoptions(threshold=np.nan)


array-creation