本文共 287 字,大约阅读时间需要 1 分钟。
#coding:utf-8import numpy as np## 改变数组的形状#将b 变成3*4 的矩阵b=np.arange(24).reshape(3,8)print(b)#将多维数组变成 1维数组a=b.ravel()print(a)#将多维数组变成 1维数组,faltten 返回的是真实的数组,需要分配新的内存空间。而ravel 返回的是数组的视图print(b.flatten())print("拉直之后:",b)#改变 b 本身的数组,会改变所作用的数组b.resize(2,12)#不改变b 本身的数组c=b.reshape(2,12)print(c)
转载地址:http://lrgli.baihongyu.com/