markflorisson88/cython — comment on commit 31b2d0cef7ae404eb92cfaaf4f50210e65f07dc4
File: tests/run/memslice.pyx line 1780
By markflorisson88:

On 20 January 2012 12:13, Dag Sverre Seljebotn

wrote:
> Hmm. I find this aspect of NumPy to be a little confusing, or perhaps "too much convenience"... In NumPy one can also do
>
> a[:, :] = b[None, :]
>
> or
>
> a[:, :] = b[:, None]
>
> (henceforth "newaxis-notation"), where None inserts a new 1-length dimension. This is what I usually do (as proof, I can't remember which of the above corresponds to a[:, :] = b[:]).
>
> The a[:, :] = b[:] notation is truly useful when one does not know the number of dimensions; but that is never the case currently in Cython.

The broadcast applies leading newaxes dimensions, i.e. b[None, :].
This corresponds to broadcasting a 1d array along the rows of a 2d
array. I agree that is is implicit and maybe confusing for new users,
but I like the compatibility with NumPy here.

> BTW, do you support newaxis-notation in Cython now? It's more general than broadcasting so should perhaps be implemented first anyway. Provided that we do want to support the more generic newaxis-notation then the a[:, :] = b[:] notation could perhaps be delayed until the question about whether we want it or not is settled -- it's easier to add it than to remove it.

That has been on my todo-list, it is not yet supported. I think it
should indeed be None, as that would be compatible with both NumPy and
our memoryviews. e.g. view.newaxis could also work if it converts to
None in other contexts, but then you'd expect numpy.nexaxis to work as
well, but Cython would try to convert that to an integer for typed
indexing.

> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/markflorisson88/cython/commit/31b2d0cef7ae404eb92cfaaf4f50210e65f07dc4#commitcomment-885558