NumPy array slice using None

后端 未结 1 1606
失恋的感觉
失恋的感觉 2020-12-08 18:29

This had me scratching my head for a while. I was unintentionally slicing an array with None and getting something other than an error (I expected an error). Instead, it r

相关标签:
1条回答
  • 2020-12-08 19:00

    Using None is equivalent to using numpy.newaxis, so yes, it's intentional. In fact, they're the same thing, but, of course, newaxis spells it out better.

    The docs:

    The newaxis object can be used in all slicing operations to create an axis of length one. newaxis is an alias for ‘None’, and ‘None’ can be used in place of this with the same result.

    A related SO question.

    0 讨论(0)
提交回复
热议问题