# Scipy基本功能

NumPy向量

``````import numpy as np
list = [1,2,3,4]
arr = np.array(list)
print (arr)
``````

``````[1 2 3 4]
``````

## 內在NumPy陣列建立

NumPy有從頭開始建立陣列的內建函式。 其中一些函式解釋如下。

`zeros(shape)`函式將建立一個用指定形狀(shape)填充`0`值的陣列。 預設`dtype``float64`。 看看下面的例子。

``````import numpy as np
print (np.zeros((2, 3)))
``````

``````array([[ 0., 0., 0.],
[ 0., 0., 0.]])
``````

`ones(shape)`函式將建立一個填充`1`值的陣列。 它在所有其他方面與`0`相同。 看看下面的例子。

``````import numpy as np
print (np.ones((2, 3)))
``````

``````array([[ 1., 1., 1.],
[ 1., 1., 1.]])
``````

`arange()`函式將建立具有有規律遞增值的陣列。 看看下面的例子。

``````import numpy as np
print (np.arange(7))
``````

``````array([0, 1, 2, 3, 4, 5, 6])
``````

``````import numpy as np
arr = np.arange(2, 10, dtype = np.float)
print (arr)
print ()"Array Data Type :",arr.dtype)
``````

``````[ 2. 3. 4. 5. 6. 7. 8. 9.]
Array Data Type : float64
``````

`linspace()`函式將建立具有指定數量元素的陣列，這些元素將在指定的開始值和結束值之間平均間隔。 看看下面的例子。

``````import numpy as np
print (np.linspace(1., 4., 6))
``````

``````array([ 1. , 1.6, 2.2, 2.8, 3.4, 4. ])
``````

## 矩陣

``````import numpy as np
print (np.matrix('1 2; 3 4'))
``````

``````matrix([[1, 2],
[3, 4]])
``````

``````import numpy as np
mat = np.matrix('1 2; 3 4')
print (mat.H)
``````

``````matrix([[1, 3],
[2, 4]])
``````

``````import numpy as np
mat = np.matrix('1 2; 3 4')
print (mat.T)
``````

``````matrix([[1, 3],
[2, 4]])
``````