用numpy制作矩阵

2021-10-17 18:46:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个5行4列的矩阵。问题是,当我运行它时,出现了一个错误“Traceback(last recent call last): 文件“C:\Users\yasini\Desktop\30.py”,第21行,in [‘ART |Ф',0.71],‘N |Ф',0.29],‘V |Ф',0.0001],‘P |Ф',0]]).整形(5,4) ValueError:新数组的总大小必须保持不变”。你知道吗

我该怎么解决?你知道吗

import numpy as np
A = np.array([['ART|ART',0], ['N|ART',1], ['V|ART',0], ['P|ART',0],
     ['ART|N',0.0001], ['N|N',0.13], ['V|N',0.43], ['P|N',0.44],
     ['ART|V',0.65], ['N|V',0.35], ['V|V',0.0001], ['P|V',0.0001],
     ['ART|P',0.74], ['N|P',0.26], ['V|P',0.0001], ['P|P',0.0001],
     ['ART|Ф',0.71], ['N|Ф',0.29], ['V|Ф',0.0001], ['P|Ф',0]]).reshape(5,4)
print (A)