numpy中flatten()函式用法
flatten是numpy.ndarray.flatten的一個函式,其官方文件是這樣描述的:
ndarray.flatten(order='C')
Return a copy of the array collapsed into one dimension.
Parameters:
order : {‘C’, ‘F’, ‘A’, ‘K’}, optional
|
|
Returns: | y : ndarray
|
即返回一個摺疊成一維的陣列。但是該函式只能適用於numpy物件,即array或者mat,普通的list列表是不行的。
例子:
1、用於array物件
1 2 3 4 5 6 7 8 |
|
2、用於mat物件
1 2 3 4 |
|
3、但是該方法不能用於list物件
1 2 3 4 5 6 7 |
|
想要list達到同樣的效果可以使用列表表示式:
1 2 |
|