numpy.reshape
(a, newshape, order='C') newshape: 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.
参考 https://numpy.org/doc/stable/reference/generated/numpy.reshape.html#numpy-reshape
意思是:新形状newshape中,有一个维度可以填写-1, -1的意思是:-1 表示这个维度的值是从x的元素总数和剩余维度推断出来的。因此,有且只有一个维度可以被设置为-1
![](https://img.haomeiwen.com/i10758717/f7d7a1fc113c7eb6.png)
网友评论