python numpy 里面的[:, None]是个什么鬼?[..., None]呢,还有[::-1]
python numpy 里面的[:, None]是个什么鬼?
·
python numpy 里面的[:, None]是个什么鬼?
遇到这种问题要学会测试性学习.举个例子就知道了.
看到没,slice时候追加了None,可以在保证数据不改变的情况下,追加一个新纬度,仅此而已.
老外的解释:
None
is an alias for NP.newaxis. It creates an axis with length 1. This can be useful for matrix multiplcation etc.
至于[..., None]是什么,还是老办法测试一下就知道啦.
呀![..., None]和[:, None]的效果是一样的.
老外的解释:
the
x[...] = ...
modifiesx
in-place;It's like
x[:] = ...
but works with arrays of any dimension (including 0d). In this contextx
isn't just a number, it's an array.Slicing: Important use of Ellipsis (...) is in slicing higher-dimensional data structures.
老外说[...]比[:]引用高维数组更方便,那我们就测试一些高维数组的slice
这次 [...]和[:]不一致啦,问题出在哪啦?
原来[...]代表了前面所有纬度的数据,而[:]只是代表一个纬度的数据,
所以老外说[...]比[:]引用高维数组更方便.
[::-1]就简答多啦:
With typeseq objects, the two colon extended slicing provides a reversed *copy* of the typeseq object as opposed to the .reverse method which reverses a typeseq object *in place* (and has no return value)
更多推荐
已为社区贡献9条内容
所有评论(0)