代码:
a = [[1, 2], [3, 4]]
# 扁平化
b = [i for item in a for i in item]
# 或
import numpy as np
npa = np.arrary(a)
b = npa.ravel()
# and
b = npa.flatten()
ravel和flatten的区别在于使用ravel形成的数据在修改后会影响np.array的源数据
上面的代码使用ravel后修改b的值npa也会变化
标签:扁平化,npa,数组,flatten,一维,np,ravel From: https://www.cnblogs.com/shallow-dreamer/p/17539181.html