numpy中使用:
- 更改为任意维度:
reshape()
- 展开为1维:
flatten()
示例代码
import numpy as np
if __name__ == '__main__':
array = np.random.random(size=(5, 10)) # (5, 10)
reshape_array = array.reshape(25, 2) # 更改为任意维度
print(reshape_array.shape) # (25, 2)
flatten_array = array.flatten() # 展为1维
print(flatten_array.shape) # (50,)
col_array = array.reshape(-1, 1) # 每个数据占用一维
print(col_array.shape) # (50, 1)