Is there a difference between matrix and array objects other than how they handle multiplication? Is there documentation somewhere about matrix objects? Are they new? Thanks, Ryan
From that it looks like exponentiation (__pow__) is also overloaded, and
Inspect is a really handy python module: import inspect import numpy print inspect.getsource(numpy.matrix) there are the additional properties: .A - get the array .T - get the transpose .H - get the conjugate transpose .I - get the inverse The other difference which isn't really obvious from looking at the source code is that matrices always have at least rank 2. I.e. .shape[0] and .shape[1] are always present for a matrix. --bb On 3/15/06, Ryan Krauss <ryanlists@gmail.com> wrote:
Is there a difference between matrix and array objects other than how they handle multiplication? Is there documentation somewhere about matrix objects? Are they new?
Thanks,
Ryan
------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmdlnk&kid0944&bid$1720&dat1642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
-- William V. Baxter III OLM Digital Kono Dens Building Rm 302 1-8-8 Wakabayashi Setagaya-ku Tokyo, Japan 154-0023 +81 (3) 3422-3380
On Wed, 15 Mar 2006, Bill Baxter wrote:
Inspect is a really handy python module: import inspect import numpy print inspect.getsource(numpy.matrix)
Another very nice option is to use ipython: ipython In [1]: import numpy In [2]: numpy.matrix? In [2]: numpy.matrix?? One ? gives some basic information: Type: type Base Class: <type 'type'> String Form: <class 'numpy.core.defmatrix.matrix'> Namespace: Interactive File: /home/abaecker/BUILDS3/BuildDir/inst_numpy/lib/python2.4/site-packages/numpy/core/defmatrix.py (and normally a doc-string, if there is one) and ?? shows you the code. Best, Arnd
On 3/15/06, Paulo J. S. Silva <pjssilva@ime.usp.br> wrote:
The other difference which isn't really obvious from looking at the source code is that matrices always have at least rank
Just to make clear. They *always* have rank two.
Not necessarily.
m = numpy.matrix('[1 2 3; 4 5 6]') mm = m[numpy.matrix('[0 1]')] m matrix([[1, 2, 3], [4, 5, 6]]) mm matrix([[[[1, 2, 3]],
[[4, 5, 6]]]])
mm.shape (1, 2, 1, 3)
Maybe that's not supposed to be possible, but with current numpy (well, 0.9.5 at least) you see it is possible to get something with type matrix that is not rank 2. --bb
Bill Baxter wrote:
On 3/15/06, *Paulo J. S. Silva* <pjssilva@ime.usp.br <mailto:pjssilva@ime.usp.br>> wrote:
> The other difference which isn't really obvious from looking at the > source code is that matrices always have at least rank
Just to make clear. They *always* have rank two.
Not necessarily.
m = numpy.matrix('[1 2 3; 4 5 6]') mm = m[numpy.matrix('[0 1]')] m matrix([[1, 2, 3], [4, 5, 6]]) mm matrix([[[[1, 2, 3]],
[[4, 5, 6]]]])
mm.shape (1, 2, 1, 3)
Maybe that's not supposed to be possible, but with current numpy (well, 0.9.5 at least) you see it is possible to get something with type matrix that is not rank 2.
A true matrix has two dimensions. The example above would appear to be a bug. Colin W.
--bb
Bill Baxter wrote:
On 3/15/06, *Paulo J. S. Silva* <pjssilva@ime.usp.br <mailto:pjssilva@ime.usp.br>> wrote:
> The other difference which isn't really obvious from looking at the > source code is that matrices always have at least rank
Just to make clear. They *always* have rank two.
Not necessarily.
m = numpy.matrix('[1 2 3; 4 5 6]') mm = m[numpy.matrix('[0 1]')] m matrix([[1, 2, 3], [4, 5, 6]]) mm matrix([[[[1, 2, 3]],
[[4, 5, 6]]]])
mm.shape (1, 2, 1, 3)
Could you enter this as a bug so it doesn't get forgotten? http://projects.scipy.org/scipy/numpy/newticket Cheers! Andrew
Andrew Straw wrote:
Bill Baxter wrote:
On 3/15/06, *Paulo J. S. Silva* <pjssilva@ime.usp.br <mailto:pjssilva@ime.usp.br>> wrote:
> The other difference which isn't really obvious from looking at the > source code is that matrices always have at least rank
Just to make clear. They *always* have rank two.
Not necessarily.
m = numpy.matrix('[1 2 3; 4 5 6]') mm = m[numpy.matrix('[0 1]')] m
matrix([[1, 2, 3], [4, 5, 6]])
mm
matrix([[[[1, 2, 3]],
[[4, 5, 6]]]])
mm.shape
(1, 2, 1, 3)
Could you enter this as a bug so it doesn't get forgotten? http://projects.scipy.org/scipy/numpy/newticket
Please check to see if it actually is still broken. I think it's fixed. -Travis
Cheers! Andrew
------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
I thought this was just expected behavior. Great. Now I can get rid of all those calls to squeeze(). Did it get logged as a bug in the first place, though, before it was fixed? Still probably worth having it in the bug tracker, though. And Travis, do you mean it's fixed in CVS or fixed in 0.9.6? Incidentally, you don't need to index a matrix with a matrix to see it, indexing a matrix with a simple python list also returns the same shape. So mm = m[numpy.matrix('[0 1]')] can also be mm = m[[0,1]] and the bug still happens in 0.9.5. Don't know about 0.9.6 or CVS though. --bb On 3/16/06, Travis Oliphant <oliphant.travis@ieee.org> wrote:
Bill Baxter wrote:
On 3/15/06, *Paulo J. S. Silva* <pjssilva@ime.usp.br <mailto:pjssilva@ime.usp.br>> wrote:
> The other difference which isn't really obvious from looking at
Andrew Straw wrote: the
> source code is that matrices always have at least rank
Just to make clear. They *always* have rank two.
Not necessarily.
m = numpy.matrix('[1 2 3; 4 5 6]') mm = m[numpy.matrix('[0 1]')] m
matrix([[1, 2, 3], [4, 5, 6]])
mm
matrix([[[[1, 2, 3]],
[[4, 5, 6]]]])
mm.shape
(1, 2, 1, 3)
Could you enter this as a bug so it doesn't get forgotten? http://projects.scipy.org/scipy/numpy/newticket
Please check to see if it actually is still broken. I think it's fixed.
-Travis
Cheers! Andrew
------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
-- William V. Baxter III OLM Digital Kono Dens Building Rm 302 1-8-8 Wakabayashi Setagaya-ku Tokyo, Japan 154-0023 +81 (3) 3422-3380
participants (7)
-
Andrew Straw
-
Arnd Baecker
-
Bill Baxter
-
Colin J. Williams
-
Paulo J. S. Silva
-
Ryan Krauss
-
Travis Oliphant