我刚开始使用 numpy。 quick start tutorial说:
The coordinates of a point in 3D space [1, 2, 1] has one axis. That axis has 3 elements in it, so we say it has a length of 3. In the example pictured below, the array has 2 axes. The first axis has a length of 2, the second axis has a length of 3.
[[ 1., 0., 0.], [ 0., 1., 2.]]
我没有收到“第一个轴的长度为 2,第二个轴的长度为 3”。我可以看到 [ 1., 0., 0.]
和 [ 0., 1., 2.]
都包含三个元素,那么为什么它们的长度不是 3 ?
最佳答案
您展示的示例还不错,但让您感到困惑。术语“轴”相当于“维度”。拿这个数组:
[[1, 2, 3],
[4, 5, 6]]
这个数组是二维的。第一维或轴有两个元素的事实只是巧合。坐标轴不是 [1, 2, 3]
和[4, 5, 6]
。
一个不太容易混淆的例子如下:
[[1, 2, 3],
[2, 3, 4],
[3, 4, 5],
[4, 5, 6]]
这个数组也是二维的,只是第一维有4个元素。形状是(4, 3)
:4行,每行3列。
关于python - numpy中轴的长度是多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64045963/