1.flatten函数能将多维数组变成一位数组
a = array([[1],[2],[3]])
a = a.flatten()
print(a)
>>>[1 2 3]
2.使用concatenate函数多个一维数组连接为一维数组
a = array([[1,2,3],[2,4,6],[9,9,9]])
a = concatenate((a[0],a[1],a[2]))
print(a)
>>>[1 2 3 2 4 6 9 9 9]
a = array([[1],[2],[3]])
a = a.flatten()
print(a)
>>>[1 2 3]
a = array([[1,2,3],[2,4,6],[9,9,9]])
a = concatenate((a[0],a[1],a[2]))
print(a)
>>>[1 2 3 2 4 6 9 9 9]
本文标题:numpy将多维数组转化为一维数组
本文链接:https://www.haomeiwen.com/subject/dyseyqtx.html
网友评论