此函数类似于numpy.array,除了它有较少的参数。 这个例程对于将 Python 序列转换为ndarray非常有用。

 

1 
2 
numpy.asarray(a, 
None) 
dtype 
None, 
3 
构 造 器 接 受 下 列 参 数 : 
数 及 描 述 
a 任 意 形 式 输 入 参 数 , 比 如 列 表 、 列 表 元 组 、 元 组 、 元 组 元 组 、 元 组 的 列 表 
dtype 通 常 , 输 入 数 的 类 型 会 应 用 到 取 回 的 ndarray 
order ' c ' 为 按 行 的 C 风 格 数 组 , ' F ' 为 按 列 的 F 丽 ran 风 格 数 组 
3 .

 

1 
2 
3 
4 
5 
6 
7 
2 
1 
# # glkł4łŔ1%J ndarray 
import numpy as np 
[122,3] 
a = np.asarray(x) 
print a 
2 
3]

 

äflJ 2 
2. 
1 
2 
3 
4 
5 
6 
7 
2 
# dtype 
import numpy as np 
x = [1, 2,31 
a = np.asarray(x, dtype = 
print a 
float) 
3.]

 

ä5J 3 
1 
2 
3 
4 
5 
6 
7 
2 
# ndarray 
import numpy as np 
a = np.asarray(x) 
print a 
2 
31

 

ä5J 4 
1 
2 
3 
4 
5 
7 
2 
# ndarray 
import numpy as np 
a = np.asarray(x) 
print a 
2,