[Numpy-discussion] numpy release
Stéfan van der Walt
stefan@sun.ac...
Fri Apr 25 09:54:24 CDT 2008
2008/4/25 Alan G Isaac <aisaac@american.edu>:
> > 2008/4/25 Alan G Isaac :
>
> >> So, if X is 2 by 2, then X[0] will be a row vector.
> >> But if X is 1 by 2, then X[0] will be a scalar?
> >> Ouch!
> >> Bye bye generic code.
>
>
> On Fri, 25 Apr 2008, Stefan van der Walt apparently wrote:
> > Yup. That's the current state of things.
>
> I do not understand.
> The released "state of things" is that for matrix ``x``
> we have that ``x[0]`` is a **matrix**.
>
> I'm not working with SVN NumPy, but my understanding
> was that as of revision r5072 ``x[0]`` always
> returns a 1d array. The core requirement was that
> ``x[0][0]`` produce the first element of the matrix.
>
> I do not have time to look at the revision right now,
> but if a matrix ``x`` we have that ``x[0]``
> can return a scalar, that is very undesirable.
In current SVN:
In [3]: x = np.matrix(np.arange(9).reshape((3,3)))
In [5]: x
Out[5]:
matrix([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
In [6]: x[0]
Out[6]: matrix([[0, 1, 2]])
In [7]: x[0,:]
Out[7]: matrix([[0, 1, 2]])
In [8]: x[0][0]
Out[8]: 0
In [9]: x[0,:][0]
Out[9]: 0
In [10]: x[:,0]
Out[10]:
matrix([[0],
[3],
[6]])
In [11]: x[:,0][0]
Out[11]: 0
In [12]: x[:2,:2][0]
Out[12]: matrix([[0, 1]])
Regards
Stéfan
More information about the Numpy-discussion
mailing list