广东十大网站建设排名,常用于做网站的软件,宝安网站建设seo信科,电商网站开发教程在进行实际的案例开发过程中#xff0c;我们经常用到矩阵、数组#xff0c;而对于这两者学习变得至关重要。在学习矩阵及相关数组的操作过程中#xff0c;不像matlab那么方便直接操作就可以了#xff0c;而是需要进行导库才可以进行操作#xff0c;python主要的学习数组和…在进行实际的案例开发过程中我们经常用到矩阵、数组而对于这两者学习变得至关重要。在学习矩阵及相关数组的操作过程中不像matlab那么方便直接操作就可以了而是需要进行导库才可以进行操作python主要的学习数组和矩阵的库有numpynumpy中的矩阵库为numpy.matlib这为我们的研究提供了基础。
实际案例中有时需要将矩阵转化为一列进行操作那么该如何操作呢python提供了reshape函数既可以直接转化。
案例
import numpy as npznp.array([[1,2,3,4],[4,5,6,7],[8,9,10,11],[12,13,14,15]])
print(initial constant:)
print(z)
print(the type of z:)
print(z.shape)
print(form of z for reshape:)
print(z.reshape(-1,1)) #reshape(-1,1)转化成为一列结果
initial constant:
[[ 1 2 3 4][ 4 5 6 7][ 8 9 10 11][12 13 14 15]]
the type of z:
(4, 4)
form of z for reshape:
[[ 1][ 2][ 3][ 4][ 4][ 5][ 6][ 7][ 8][ 9][10][11][12][13][14][15]]Process finished with exit code 0