相关疑难解决方法(0)

What does -1 mean in numpy reshape?

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]表示最后一个元素.你能解释一下吗?

python numpy

354
推荐指数
9
解决办法
22万
查看次数

标签 统计

numpy ×1

python ×1