what would you expect A[none] to do?
![](https://secure.gravatar.com/avatar/0b7d465c9e16b93623fd6926775b91eb.jpg?s=120&d=mm&r=g)
In my case, what it does is: A.shape = (5760,) A[none] -> (1, 5760) In my case, use of none here is just a mistake. But why would you want this to be accepted at all, and how should it be interpreted?
![](https://secure.gravatar.com/avatar/b4f6d4f8b501cb05fd054944a166a121.jpg?s=120&d=mm&r=g)
On Do, 2015-12-31 at 11:36 -0500, Neal Becker wrote:
We have `np.newaxis` with `np.newaxis is None` for the same thing. `None` inserts a new axes, it is documented to do so in the indexing documentation, so I will ask you to check it if you have more questions. If you want a noop, you should probably use `...` or `Ellipsis`. - Sebastian
![](https://secure.gravatar.com/avatar/342bd0a61c7081db529c856d3bcd9545.jpg?s=120&d=mm&r=g)
Slicing with None adds a new dimension. It's a common paradigm, though usually you'd use A[np.newaxis] or A[np.newaxis, ...] instead for readibility. (np.newaxis is None, but it's a lot more readable) There's a good argument to be made that slicing with a single None shouldn't add a new axis, and only the more readable forms like A[None, :], A[..., None], etc should. However, that would rather seriously break backwards compatibility. There's a fair amount of existing code that assumes "A[None]" prepends a new axis. On Thu, Dec 31, 2015 at 10:36 AM, Neal Becker <ndbecker2@gmail.com> wrote:
![](https://secure.gravatar.com/avatar/697900d3a29858ea20cc109a2aee0af6.jpg?s=120&d=mm&r=g)
TBH, I wouldn't have expected it to work, but now that I see it, it does make some sense. I would have thought that it would error out as being ambiguous (prepend? append?). I have always used ellipses to make it explicit where the new axis should go. But, thinking in terms of how regular indexing works, I guess it isn't all that ambiguous. Ben Root On Thu, Dec 31, 2015 at 11:56 AM, Joe Kington <joferkington@gmail.com> wrote:
![](https://secure.gravatar.com/avatar/97c543aca1ac7bbcfb5279d0300c8330.jpg?s=120&d=mm&r=g)
On Thu, Dec 31, 2015 at 12:10 PM, Benjamin Root <ben.v.root@gmail.com> wrote:
Yeah, I'm not really a fan of the rule that indexing with too-few axes implicitly adds a "..." on the right A[0] -> A[0, ...] but given that we do have that rule, then A[None] -> A[None, ...] does make sense. -n -- Nathaniel J. Smith -- http://vorpus.org
![](https://secure.gravatar.com/avatar/b4f6d4f8b501cb05fd054944a166a121.jpg?s=120&d=mm&r=g)
On Do, 2015-12-31 at 11:36 -0500, Neal Becker wrote:
We have `np.newaxis` with `np.newaxis is None` for the same thing. `None` inserts a new axes, it is documented to do so in the indexing documentation, so I will ask you to check it if you have more questions. If you want a noop, you should probably use `...` or `Ellipsis`. - Sebastian
![](https://secure.gravatar.com/avatar/342bd0a61c7081db529c856d3bcd9545.jpg?s=120&d=mm&r=g)
Slicing with None adds a new dimension. It's a common paradigm, though usually you'd use A[np.newaxis] or A[np.newaxis, ...] instead for readibility. (np.newaxis is None, but it's a lot more readable) There's a good argument to be made that slicing with a single None shouldn't add a new axis, and only the more readable forms like A[None, :], A[..., None], etc should. However, that would rather seriously break backwards compatibility. There's a fair amount of existing code that assumes "A[None]" prepends a new axis. On Thu, Dec 31, 2015 at 10:36 AM, Neal Becker <ndbecker2@gmail.com> wrote:
![](https://secure.gravatar.com/avatar/697900d3a29858ea20cc109a2aee0af6.jpg?s=120&d=mm&r=g)
TBH, I wouldn't have expected it to work, but now that I see it, it does make some sense. I would have thought that it would error out as being ambiguous (prepend? append?). I have always used ellipses to make it explicit where the new axis should go. But, thinking in terms of how regular indexing works, I guess it isn't all that ambiguous. Ben Root On Thu, Dec 31, 2015 at 11:56 AM, Joe Kington <joferkington@gmail.com> wrote:
![](https://secure.gravatar.com/avatar/97c543aca1ac7bbcfb5279d0300c8330.jpg?s=120&d=mm&r=g)
On Thu, Dec 31, 2015 at 12:10 PM, Benjamin Root <ben.v.root@gmail.com> wrote:
Yeah, I'm not really a fan of the rule that indexing with too-few axes implicitly adds a "..." on the right A[0] -> A[0, ...] but given that we do have that rule, then A[None] -> A[None, ...] does make sense. -n -- Nathaniel J. Smith -- http://vorpus.org
participants (5)
-
Benjamin Root
-
Joe Kington
-
Nathaniel Smith
-
Neal Becker
-
Sebastian Berg