numpy_2(多维数组降为一维reval,flatten)

#coding=utf-8
#anthor:ABian

import numpy as np

x=np.arange(3,5,0.2)
x=x.reshape(2,5)

print(x)
#ravel和flatten可以将数组降为一维,默认为行优先
print(x.ravel())
print(x.flatten())
#改为列优先
print(x.ravel('F'))
print(x.flatten('F'))
#二者差别,flatten返回的是拷贝,ravel是直接指向
x.ravel()[0]=10
print(x)
x.flatten()[9]=10#因为返回的是拷贝,输出以后能发现第十个数没有改变
print(x)

你可能感兴趣的:(机器学习之旅,numpy)