# NumPy - 数组函数

## numpy.asarray

`numpy.asarray(a, dtype=None, order=None)`

Sr.No.Parameter & 描述
1

a

2

dtype

3

order

C(行)或F(列)。 C是默认值

```# 将list列表转换为 ndarray
import numpy as np

x = [1,2,3]
a = np.asarray(x)
print a```

`[1  2  3] `

```# dtype is set
import numpy as np

x = [1,2,3]
a = np.asarray(x, dtype = float)
print a```

`[ 1.  2.  3.] `

```#ndarray from tuple
import numpy as np

x = (1,2,3)
a = np.asarray(x)
print a```

`[1  2  3]`

```# ndarray from list of tuples
import numpy as np

x = [(1,2,3),(4,5)]
a = np.asarray(x)
print a```

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

## numpy.frombuffer

`numpy.frombuffer(buffer, dtype=float, count=-1, offset=0)`

Sr.No.Parameter & 描述
1

buffer

2

dtype

3

count

4

offset

```import numpy as np
s = 'Hello World'
a = np.frombuffer(s, dtype = 'S1')
print a```

`['H'  'e'  'l'  'l'  'o'  ' '  'W'  'o'  'r'  'l'  'd']`

## numpy.fromiter

`numpy.fromiter(iterable, dtype, count=-1)`

Sr.No.Parameter & 描述
1

iterable

2

dtype

3

count

```# 使用range函数创建列表对象
import numpy as np
list = range(5)
print list```

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

```# 从list列表中获取迭代器对象
import numpy as np
list = range(5)
it = iter(list)

# 使用迭代器创建ndarray
x = np.fromiter(it, dtype = float)
print x```

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

### 相关文章

Serverless入门课 -〔蒲松洋（秦粤） - 〕

Python乌龟模块没有响应正在发出的击键

pygame检测绘制的圆形精灵是否被点击失败