# NumPy - 來自數值範圍的陣列

## `numpy.arange`

``````numpy.arange(start, stop, step, dtype)
``````

1. `start` 範圍的起始值，預設為`0`
2. `stop` 範圍的終止值(不包含)
3. `step` 兩個值的間隔，預設為`1`
4. `dtype` 返回`ndarray`的資料型別，如果沒有提供，則會使用輸入資料的型別。

### 範例 1

``````import numpy as np
x = np.arange(5)
print x
``````

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

### 範例 2

``````import numpy as np
# 設定了 dtype
x = np.arange(5, dtype =  float)
print x
``````

``````[0.  1.  2.  3.  4.]
``````

### 範例 3

``````# 設定了起始值和終止值引數
import numpy as np
x = np.arange(10,20,2)
print x
``````

``````[10  12  14  16  18]
``````

## `numpy.linspace`

``````numpy.linspace(start, stop, num, endpoint, retstep, dtype)
``````

1. `start` 序列的起始值
2. `stop` 序列的終止值，如果`endpoint``true`，該值包含於序列中
3. `num` 要生成的等間隔樣例數量，預設為`50`
4. `endpoint` 序列中是否包含`stop`值，預設為`ture`
5. `retstep` 如果為`true`，返回樣例，以及連續數位之間的步長
6. `dtype` 輸出`ndarray`的資料型別

### 範例 1

``````import numpy as np
x = np.linspace(10,20,5)
print x
``````

``````[10.   12.5   15.   17.5  20.]
``````

### 範例 2

``````# 將 endpoint 設為 false
import numpy as np
x = np.linspace(10,20,  5, endpoint =  False)
print x
``````

``````[10.   12.   14.   16.   18.]
``````

### 範例 3

``````# 輸出 retstep 值
import numpy as np

x = np.linspace(1,2,5, retstep =  True)
print x
# 這裡的 retstep 為 0.25
``````

``````(array([ 1.  ,  1.25,  1.5 ,  1.75,  2.  ]), 0.25)
``````

## `numpy.logspace`

``````numpy.logscale(start, stop, num, endpoint, base, dtype)
``````

`logspace`函式的輸出由以下引數決定：

1. `start` 起始值是`base ** start`
2. `stop` 終止值是`base ** stop`
3. `num` 範圍內的數值數量，預設為`50`
4. `endpoint` 如果為`true`，終止值包含在輸出陣列當中
5. `base` 對數空間的底數，預設為`10`
6. `dtype` 輸出陣列的資料型別，如果沒有提供，則取決於其它引數

### 範例 1

``````import numpy as np
# 預設底數是 10
a = np.logspace(1.0,  2.0, num =  10)
print a
``````

``````[ 10.           12.91549665     16.68100537      21.5443469  27.82559402
35.93813664   46.41588834     59.94842503      77.42636827    100.    ]
``````

### 範例 2

``````# 將對數空間的底數設定為 2
import numpy as np
a = np.logspace(1,10,num =  10,  base  =  2)
print a
``````

``````[ 2.     4.     8.    16.    32.    64.   128.   256.    512.   1024.]
``````