A numpy matrix can be reshaped into a vector using reshape function with parameter -1. But I don't know what -1 means here.
For example:
a = numpy.matrix([[1, 2, 3, 4], [5, 6, 7, 8]])
b = numpy.reshape(a, -1)
Run Code Online (Sandbox Code Playgroud)
The result of b is: matrix([[1, 2, 3, 4, 5, 6, 7, 8]])
有谁知道-1在这里意味着什么?并且似乎python赋予-1几个含义,例如:array[-1]表示最后一个元素.你能解释一下吗?