最近一直在学习Python, Numpy是一个非常使用的库。最近在研究。
学习必去的地方Numpy官网
中文快速入门
现在还处于初级阶段,汇总一下遇到的问题。
reshape的第二个参数。
new shape int or tuple of ints
The new shape should be compatible with the original shape.
If an integer, then the result will be a 1-D array of that length.
One shape dimension can be -1. In this case, the value is
inferred from the length of the array and remaining dimensions.
有时候会看到不是类似(4,3)这样的输入,有时候会看到其中一个是-1.
这个时候,最后的形状会根据已知的一维来进行计算。
举个例子,如果数组中有20个元素,这时候调用reshape(-1, 5),数组会自动转换为(4*5)的矩阵。