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[...] = ... modifies x in-place; 

It's like x[:] = ... but works with arrays of any dimension (including 0d). In this context x 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)

 

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐